Categories > TinyButStrong general >

conditional onload template

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Jared
Date: 2005-12-29
Time: 00:26

conditional onload template

Hello, Can you tell me why this is not working.

[onload;file=[var.conf.action;if  [val]-=+ 2;then 'template/PlatinumGreen/main1.html';else 'template/PlatinumGreen/main2.html']]

getting the error
TinyButStrong Error (Tag definition): Can't found the end of the tag '[var.conf.actio...'.

TinyButStrong Error (Parameter 'file'): Field [onload] : unable to read the file '[var.conf.action;if -=+ 2'. This message can be cancelled using parameter 'noerr'.
]
By: Jared
Date: 2005-12-29
Time: 02:17

Re: conditional onload template

I'm trying different ways to get some display logic into my template.

Why won't this work either:
[onload_1;tplvars;test='template/PlatinumGreen/main1.html'; when [var.conf.action] -=+ 2]
[onload_1;tplvars;test='template/PlatinumGreen/main2.html'; when [var.conf.action] +=- 3]
[onload_1;tplvars;test='template/PlatinumGreen/main1.html'; default]
By: Jared
Date: 2005-12-29
Time: 02:37

Re: conditional onload template

Ok, so I found a solution to my problem.

I was trying to make a single file, my index.html file, contain logic to include different templates based on a global php variable.

Here is what I came up with:

[onload_1;block=begin;when [var.conf.action] = 3]
  [onload_2;tplvars;test='template/PlatinumGreen/main2.html']
[onload_1;block=end]
[onload_1;block=begin;when [var.conf.action] = 4]
  [onload_2;tplvars;test='template/PlatinumGreen/main2.html']
[onload_1;block=end]
[onload_1;block=begin;default]
  [onload_2;tplvars;test='template/PlatinumGreen/main1.html']
[onload_1;block=end]
[onload_3;file=[var..tplvars.test];htmlconv=no]

This does not seem very elegant, but it works :P
By: Skrol29
Date: 2005-12-29
Time: 14:48

Re: conditional onload template

I don't know why your first snippet returns such an error message. I will test it. But why don't you simply doint this case operation at the PHP side ?

Like:
PHP:
$page = 'main1.html';
if ($conf['action']>=3) $page = 'main2.html';

HTML:
[onload;file=[var.page]]
By: Jared
Date: 2005-12-29
Time: 19:16

Re: conditional onload template

> But why don't you simply doint this case operation at the PHP side ?

This is the problem I ran into: I coded my template system so that the main application uses one index.html that is layed out with blocks of template code. This worked great for the initial template, but then I had another design developed. I do not want to break the old template, and I want to give the flexibility to have the designers create templates that look nothing like the original.

So what seemed like the best solution was to use the original index.html that was loaded via my php application, and then include some display logic inside that template to control the layout.

So while my old template is all layed out in blocks, my new template is very dynamic and I didn't have to change any of the application code.

Does this make sense?
By: Skrol29
Date: 2005-12-30
Time: 16:29

Re: conditional onload template

Hello Jared,

It seems that TBS has a bug on the snippet you first submitted.
I'm working on it.
By: Jared
Date: 2005-12-30
Time: 18:42

Re: conditional onload template

Thanks!
By: Skrol29
Date: 2006-01-02
Time: 20:21

Re: conditional onload template

OK, the bug is fixed. TBS 2.05.5 is now available for download.
There is another mini bug fixed, the changelog will be soon written.

Thanks again...
By: Jared
Date: 2006-01-02
Time: 20:50

Re: conditional onload template

Thanks!