Categories > TinyButStrong general >

Repeat a block twice with a single MergeBlock

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: jordi
Date: 2009-04-19
Time: 17:18

Repeat a block twice with a single MergeBlock

Can I repeat the same block twice in the same template?

i.e

PHP:
$TBS->MergeBlock("myarr",$myarr);


HTML:

.
.
.
<h1>Dictionary</h1>
[myarr;block=_] Word [myarr.key] means [myarr.val]
.
.
.
<h1>TAG Cloud</h1>
[myarr;block=_] <a href="search?word=[myarr.key]">[myarr.val]</a>
.
.
.


In the tag cloud I would like to repeat all the array traversal , i.e. reset the array and repeat all the array.

Now I solve am solving it like this:

PHP:
$TBS->MergeBlock("myarr1",$myarr);
$TBS->MergeBlock("myarr2",$myarr);

Can it be solved with just one MergeBlock?
By: TomH
Date: 2009-04-19
Time: 19:06

Re: Repeat a block twice with a single MergeBlock

Try

<myblock>
<h1>Dictionary</h1>
Word [myarr.key;block=myblock] means [myarr.val]
.
.
.
<h1>TAG Cloud</h1>
<a href="search?word=[myarr.key]">[myarr.val]</a>
</myblock>
.
By: Skrol29
Date: 2009-04-19
Time: 21:57

Re: Repeat a block twice with a single MergeBlock

Hi Jordi,

Two blocks cannot have the same name. But you can merge several blocks with one MergeBlock().

HTML:
<h1>Dictionary</h1>
[myarr1;block=_] Word [myarr1.key] means [myarr1.val]
.
.
.
<h1>TAG Cloud</h1>
[myarr2;block=_] <a href="search?word=[myarr2.key]">[myarr2.val]</a>

PHP:
$TBS->MergeBlock("myarr1,myarr2",$myarr);
By: TomH
Date: 2009-04-19
Time: 23:46

Re: Repeat a block twice with a single MergeBlock

Skrol,

I tested my proposed solution above and it does work.

Should it not work? - or do I misunderstand precisely what you mean in your post.
By: jordi
Date: 2009-04-20
Time: 11:17

Re: Repeat a block twice with a single MergeBlock

Tom thanks but I didn't explain myself properly. I wanted (more or less):

with myarr
for i = 1 to 10
print myarr[i]
next

with myarr
for i = 1 to 10
print myarr[i]
next

By: jordi
Date: 2009-04-20
Time: 11:26

Re: Repeat a block twice with a single MergeBlock

Thank you Skrol29!

I haven't looked at how TBS works internally. Now I can get the idea.

It's a good shortcut merging several blocks in one MergeBlock.

My question was because I use TBS to generate apache, bind and other .CONF config files and I have different templates that mix and match on differents servers.

If I could reset an array, I could use the same array of records in different places without messing with the array ID.

Now I keep every variable in an array and increment it in each use which complicates the process a little.

If TBS parses the template in a linear way, it would be great to have an additional parameter RESET/REWIND in the Block Syntax, i.e.:

[block1;block=begin;RESET] or [block1;block=tr;REWIND]

so that TBS could ReMerge or reset the array and process it again.

Thank you very much, wonderful support!
By: jordi
Date: 2009-04-20
Time: 11:29

Re: Repeat a block twice with a single MergeBlock

BTW, I know TBS is a PHP template system. I started using it for a few small websites coming from WML (http://thewml.org/) and now I use it with PHP-CLI for every template system I need.

Regards.
By: Skrol29
Date: 2009-04-20
Time: 23:56

Re: Repeat a block twice with a single MergeBlock

Hi TomH,

I didn't see your reply, probably because I posted mine only two hours after you without refreshing my browser.

Your solution give a different result. With your snipper the <h1> tags are repeated. I thing Jordi don"t want them repeated.
By: jordi
Date: 2009-04-21
Time: 03:41

Re: Repeat a block twice with a single MergeBlock

Right! I don't want that H1 repeated.

Have you thought about [block1;block=tr;REWIND]?

Regards.