ds3464 2018-07-04 00:42
浏览 53

TinyButStrong:TBS对象访问一个全局变量而不访问另一个

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();
  • 写回答

1条回答 默认 最新

  • dongshenyu4638 2018-07-05 01:55
    关注

    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();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教