Categories > TinyButStrong general >

Can subtemplate results be forwarded back to main php into a variable?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Pirjo Posio
Date: 2007-09-24
Time: 19:48

Can subtemplate results be forwarded back to main php into a variable?

Hi,
I've tried to use TBS main template + subtemplate combination for this:
I want to store messages like this in a MySQL field:
'The name [var.name] needs [var.amount] pieces.'
I'd like to use a TBS string subtemplate to parse the variables in there.
But sometimes I don't want TBS to Show the result (echo), as it normally will.
I am able to end the subtemplate by having the result in a variable.
How can I get it back to the main php script in a variable?
If subtemplate is not good for this, is there some other way?
By: TomH
Date: 2007-09-24
Time: 22:13

Re: Can subtemplate results be forwarded back to main php into a variable?

My Dear Ms Pirjo,

I haven't tested this with sub-scripts... but I have tricked my scripts with the export_plugin something like this
<!-- fake run the export_plugin at the top of the page -->
<!-- this makes the exported vars available throughout -->
<dump><!-- [blk_test.name; block=dump; export] [blk_test.age] --> </dump>
<!-- use some of the exported vars here -->
First name : [blk_test[0].name]
First age : [blk_test[0].age]
<!-- run another TBS block in the middle of the page -->
<table width="200" border='1' bgcolor='cyan'>
<tr><th>Name</th><th>Age</th></tr>
<tr><th>[blk_test2.name; block=tr;] </th><th>    [blk_test2.age]</th></tr>
</table>
<!-- use more of the exported vars here -->
Third name : [blk_test[2].name]
Third age : [blk_test[2].age]

Maybe the basic idea of this export plugin will help somehow.

By: Skrol29
Date: 2007-09-25
Time: 03:24

Re: Can subtemplate results be forwarded back to main php into a variable?

Hi Pirjo,

Maybe you don't need subtemplates.
You can just swap the current main template with another small template, do the merge with $TBS->Show(TBS_NOTHING) in order to ahve no output , and retreive the result with $TBS->Source.
By: Pirjo Posio
Date: 2007-09-25
Time: 15:50

Re: Can subtemplate results be forwarded back to main php into a variable?

Thank you so much, Skrol29, whose comment this time was the winner (applauds)!
TomH had an interesting comment also, and I can use that elsewhere, so thank you!

I posted my solution to the Tips&Tricks Forum, in the same thread with other Multi-language stuff, since this solution can be used for language translation, as well as for other applications, where you possibly need variables inside strings and need to merge those separately from your main template.
Here's the link: http://www.tinybutstrong.com/forum.php?msg_id=8195