Categories > TinyButStrong general >

include file or show text depnding on variable

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: RwD
Date: 2005-10-26
Time: 23:30

include file or show text depnding on variable

Now, perhaps it is simply the time because I want something simple but can't work out the logic :|

I am freshing up some old code to use to build a new website and in there something is done I want to do differently.

I have two variables $template and $text. If $template has a value I want to include the file that $template should point to. If $template is not set I want to include the text that is in the $text variable.

Simple logic to include a file would be [onload;file=[var.$template]; protect=no]. And simple logic to display the text could be [var.$template; protect=no] But I cannot work out how to make it one or the other :|
By: howman
Date: 2005-10-27
Time: 04:59

Re: include file or show text depnding on variable

What if you do it as two sub-templates?  One template would have  [onload;file=[var.$template]; protect=no].  The other template will have [var.$template; protect=no].  The main template will have something like [var.$which_template; protect=no].  You can put logic in the php controller script to determine $which_template.

Just an idea.  Hope it helps.

H
By: RwD
Date: 2005-10-27
Time: 07:27

Re: include file or show text depnding on variable

Current situation is that the php script sets $template to 'default.htm' whenever $template is empty. default.htm only has [var.text; protect=no] as contents. And I want to eliminate template files as I have a large number where a lot of them have unclear functions (they do have a function) or are very very small like 'default.thm' this could all be done in one template I am sure...
By: RwD
Date: 2005-10-27
Time: 21:50

Re: include file or show text depnding on variable

Right now I did this and it seems to be working:
[onload; block=begin; when '[var.html_template]' != '']
    [contentinclude;file=[var.dir.tmpl][var.html_template]; htmlconv=look; protect=no]
[onload; block=end]
[onload; block=begin; default]
    [var.page_html; htmlconv=look; protect=no]
[onload; block=end]

Can anybody tell me if this is actually the way to go?
By: RwD
Date: 2005-10-27
Time: 22:45

Re: include file or show text depnding on variable

I moved away from this solution, and load the correct template from the php page directly. had to rewrite stuff, but got some more controls now. But perhjaps for future reference people would like an answer to my question anyway?
By: Skrol29
Date: 2005-10-28
Time: 00:30

Re: include file or show text depnding on variable

Maybe:
[onload;if [var.template]=='';then [var.text;protect=no]; else [var.template;file=[val]];htmlconv=no]
But I didn't try it.