Forums / Cotonti / Support / ParseBlock Help

medj
#1 2009-02-23 02:48
Hello, I was wondering if someone could help me out with what I'm trying to accomplish.

I have a function that will parse tags in HTML. I know users of Seditio and Cotonti are all familiar with this method.

First off, here is some code:

class Parser {
  function ParseTags($Template, $ParseTags) {
    $Template = file_get_contents($Template);
    foreach($ParseTags as $UnParsed => $Parsed){      
      $Template = str_replace("{".$UnParsed."}", $Parsed, $Template);
      }
    return $Template;
    }

This will basically look at one of my HMTL files and convert any tags into the data that should be displayed for that page. This works fine.

My question is basically if anyone knows how to implement a parseblock function. A very simple one in which on my HTML file I can have the following code:

{START: SHOW_NEWS}
{row_news_title}
{row_news_body}
{END: SHOW_NEWS}

And basically it would repeat this for as many news posts as I want to show on a page.

Even if someone has a link for me to learn how to do this, that would be fine. I was searching for "ParseBlock" and didn't come up with any help.

Thanks.
Trustmaster
#2 2009-02-23 02:57
Are you reinventing XTemplate?
May the Source be with you!
medj
#3 2009-02-23 03:29
Um, to be honest, I don't know what XTemplate is but I'm gonna look into it.


EDIT:
I just took a quick look at XTemplate.
All I have to do is include the xtemplate.class file. From what I understand, this should give me all the functionality that I was looking for.
Thanks for this idea, I will look more into XTemplate later on when I get back home.
This post was edited by medj (2009-02-23 03:44, 15 years ago)
Trustmaster
#4 2009-02-23 04:31
You don't need to include anything, mate! XTemplate is what Seditio/Cotonti uses to render TPL files. So you just use it this way:
$my_tpl = new XTemplate('path/to/file.tpl');
$my_tpl->assign(array(
'TEST_1' => $some_var,
'TEST_2' => $another
));

$my_tpl->parse('MAIN.MY_BLOCK');

$my_tpl->parse('MAIN'); // Parse main block
$output = $my_tpl->text('MAIN'); // return contents
$my_tpl->out(); // output contents
May the Source be with you!
Kilandor
#5 2009-02-23 06:22
You can create a new Xtemplate with any file, it could be called .txt, .html it doesnt' matter.

So jsut create a PHP file, and run your html file through xtemplate.
medj
#6 2009-02-23 14:45
Thanks a lot for the help guys.

Is it just me or does the "copy to clipboard" function not work?
Orkan
#7 2009-02-23 22:32
# medj : Is it just me or does the "copy to clipboard" function not work?

Is working for me, using FF2... what is your specs?
Perl - the only language that looks the same before and after RSA encryption.
Trustmaster
#8 2009-02-23 22:59
Neither it it works for me: Ubuntu 8.10, FireFox 3.0.6.
May the Source be with you!
medj
#9 2009-02-24 00:19
I have Windows XP, Firefox 3.0.6. as well.
Kilandor
#10 2009-02-24 07:40
Same, doesn't work for me, but XP, FF 3.0.6
kripteks
#11 2009-02-24 08:24
Verifi script blocking
kripteks();