Categories > TinyButStrong general >

Loading a dynamic subtemplate

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: XorCo
Date: 2011-11-03
Time: 12:40

Loading a dynamic subtemplate

Hey,

My subtemplate renders okay but the script is executed differently when the page is loaded dynamically. Let me explain.

I have a main template (template.htm) with this line:
[onload;script=sub.php;subtpl]

Works perfectly but when I want sub.php do be a variable and load my subtemplate dynamically the script is executed differently:
In template.htm:
[onload;script=[loadTmpl];subtpl]

I have in index.php:
$loadTmpl = "sub.php";

$TBS = new clsTinyButStrong;
$TBS->LoadTemplate('template.htm');
$TBS->MergeField('loadTmpl',$loadTmpl);

$TBS->Show(TBS_OUTPUT);

In sub.php I have:
if ( isset($this) ) { $TBS = $this; } else { include_once('TEMPLATE/tbs_class_php5.php'); $TBS = new clsTinyButStrong; }

$content = "blabla";
addLog("I write this in a file"); // This function is not executed when I run it dynamically, otherwise it works perfectly.

$TBS->LoadTemplate('subtemplate.htm');
$TBS->MergeField('content',$content);

$TBS->Show(TBS_OUTPUT);


I assume it is because [loadTmpl] has to be merged before the file can be included or something like that?

Hope you can help me on this.
Thank you,

Alex
By: Skrol29
Date: 2011-11-03
Time: 14:07

Re: Loading a dynamic subtemplate

Hi,

Yes, the [onload] field is merged before [loadTpml] is merged. So the value of [loadTpml] is not correct at this moment.

But parameter "script" allows [var] fields. So you can code:
[onload;script=[var.loadTmpl];subtpl]
But you have to ensure that $loadTmpl is set as a global variable.

By the way, in TBS 3.8.0 which is available in beta version, it will be possible to change the scope of [var] fields.
By: XorCo
Date: 2011-11-04
Time: 12:16

Re: Loading a dynamic subtemplate

Still doesn't do what I want =(
I even tried with the onshow method but those two following lines work differently
[onshow;script=[var.loadTmpl];subtpl]
[onshow;script=sub.php;subtpl]

Actually I just wanna have the TBS version of the PHP "include($page)" function.
Is there any other way for including a page dynamically?

Thanks
By: Skrol29
Date: 2011-11-04
Time: 13:57

Re: Loading a dynamic subtemplate

Hi,

This is not normal that
[onshow;script=[var.loadTmpl];subtpl]
and
[onshow;script=sub.php;subtpl]
give different results.
Can you double check that [var.loadTmpl] is what you expect at this moment.
For example, add somewhere:
[onshow;if 'sub.php'='[var.loadTmpl]';then 'ok';else 'grrr']
By: XorCo
Date: 2011-11-04
Time: 17:36

Re: Loading a dynamic subtemplate

Is does show OK.
Maybe because I should add a special parameter.
What's the getbody parameter for, I try to understand it from the manual but I still don't understand it?
By: XorCo
Date: 2011-11-04
Time: 17:59

Re: Loading a dynamic subtemplate

Just to be clear.

In my sub.php I just have the two following lines:
<?php
print "This is printed in both cases";

// The following code is not executed when I use [var.loadTmpl]
$stream = fopen("log.txt","a");
$str = date("d/m/Y - H:i:s")." - ".$str."\n";
fwrite($stream,$str);
fclose($stream);
?>

It is like

[onshow;script=[var.loadTmpl];subtpl]

only returns the output which is visible, without executing the rest which is not visible.
I am beginning to feel desperate :(
Thanks for helping me out though.

Alex
By: Skrol29
Date: 2011-11-04
Time: 23:07

Re: Loading a dynamic subtemplate

Hi,

I've tested your snippet and it works normal for me.
I can say that parameter "script" first try to merge any [var] fields in its value and then continue to process.
Thus the process is exactly the same in both case (with or without a var field) since the correct PHP subscript is found.