I have a base template that then builds sub-templates.
Template side:
<header>
{onload;file={var.flag;if [val]=1;then 'nav.tpl';else ''}}
</header>
<main>
{onload;file={var.templatePath}}
</main>
So the main
tag is populated with the sub-template, but the header is not. It is saying, TinyButStrong Error in field {var.flag...}: the key 'flag' does not exist or is not set in VarRef. (VarRef seems refers to $GLOBALS) This message can be cancelled using parameter 'noerr'.
, but in fact it does exist in the VarRef
array along with templatePath
.
Php Side:
global $templatePath, $flag;
$this->tbs->LoadTemplate($pageTemplateFile);
if(true){$flag = 0;}
$this->tbs->Show();
By default in TBS, the [var] fields refer to $GLOBALS (which is the same as variables locally declared with « global »).
Nevertheless in your snippet, the value of $flag is NULL when the template is loaded because it is declared with « global » but no value is assigned to it yet ($flag = 0 is assigned after the template is loaded). So for PHP : is_set($flag) will return false when [onload] fields are processed.
So you have to use [onshow] fields instead of [onload], or simply set $flag before the loading. Like this :
global $templatePath, $flag;
if(true){$flag = 0;}
$this->tbs->LoadTemplate($pageTemplateFile);
$this->tbs->Show();