Categories > TinyButStrong general >

Replace variable within template with TBS function

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Intermedi8
Date: 2007-01-29
Time: 20:38

Replace variable within template with TBS function

Hi people, is there a way to replace an easy variable in an template with a TBS function? my problem is the following:

i got an index.html template file in which different dynamic subtemplates should be included. at the moment i use tags like [onload;script=sources/header.php;subtpl] to load the header subtemplate into my index file.

but what i want is an easy and short tag like [var.header], so the webdesigners didnt get confused. it also makes things easier when working with a WYSIWYG editor to change the template design, caus a lot of those long tags distorts the whole layout.

so is there a way to replace a simple TBS variable within a template with the script load function?
By: sheepy
Date: 2007-01-30
Time: 04:20

Re: Replace variable within template with TBS function

I do a preg_replace to replace SSI with [onload], so that our designer can use SSI in dreamweaver.
Our dreamweaver MX 2004 does not support SSI in parent hierachy (no .../whatever.html), however when they're in same folder it works perfectly.  Or so I think, I didn't hear complains.

Code:
$src = & $tbs->Source;
$src = preg_replace('~<!--#include\s+(?:virtual|file)\s*=\s*"?([^"\s\]]+)"?\s*-->~','[onload;file=$1]', $src);

HTML:
<!--#include file="_header.html" -->
...
<!--#include file="_footer.html" -->
By: sheepy
Date: 2007-01-30
Time: 04:24

Re: Replace variable within template with TBS function

When you need to include PHP script instead of HTML template, you can do it with normal field:

http://www.tinybutstrong.com/manual.php#html_subtemplate

(The section is at end of manual which may take some time to load)
By: Intermedi8
Date: 2007-01-30
Time: 09:32

Re: Replace variable within template with TBS function

thx sheepy, but this did not solve my problem. i already know how to run a script as subtemplate, thats not it. and when i use ur first answer i also got the same problem, just the syntax changes. i dont want any parameters or a file name within my html template, just a simple variable like [var.header] or even better [header] which will be replaced at run time with the script load function. thx anyways ... any other solutions?
By: sheepy
Date: 2007-01-30
Time: 09:58

Re: Replace variable within template with TBS function

Well, removing the filename can be easily done, if you want no parameter as well then you need some undocumented feature:

HTML
[header]

PHP
$TBS->Protect = false; // Disable tag protection
$TBS->MergeField('header','[onload;subtpl=template/header.php]');
$TBS->Protect = true; // Enable tag protection
$TBS->MergeField('onload');