0

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();
k.wig
  • 39
  • 1
  • 7
  • I don't think pulling in a global variable is the same as making it a local property in this example. I don't know anything about tbs, but based on the error, it sounds like it agrees with me. var.flag probably requires that flag is a property on the VarRef object (like $this->flag), not just present at the time in the VarRef file. – Anthony Jul 04 '18 at 00:47
  • @Anthony that wouldn't make sense when $templePath is define exactly the same way – k.wig Jul 04 '18 at 11:47

1 Answers1

1

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();
Skrol29
  • 5,402
  • 1
  • 20
  • 25