【问题标题】:how to use vbulletin variables globally?如何全局使用 vbulletin 变量?
【发布时间】:2013-07-22 03:32:11
【问题描述】:

我想在 vbulletin 的另一个页面上使用 {vb:raw human_verify} ?

当我在另一个模板中使用这个变量时,它不起作用。

它在某些模板(注册、搜索、..)上完美运行,但在其他模板中无法正常运行..

我已尝试添加新插件,使 vars 成为全局变量:

vB_Template::preRegister('activity_home',array('includedphp ' => $includedphp));  

但这仅适用于新的(自定义)vbulletin vb:raw 变量。

如何克服这个问题?

提前致谢

【问题讨论】:

    标签: php variables vbulletin


    【解决方案1】:

    我假设您使用的是 vb4,并且您的变量设置在 includephp 中。 然后你需要改变:

    activity_home

    使用需要使用变量的模板名称(如果要将其添加到多个模板中,请多次使用)。所以基本上:使用“FORUMHOME”将其放入您的论坛主页或“标题”将其放在标题中......

    This link 可能会有所帮助(请参阅“保存到数组并预注册以在现有/库存模板中使用”部分)。 希望对您有所帮助。

    编辑:

    $templater = vB_Template::create('mytemplate'); // Define a template
    $templater->register('my_var', $my_var); // define some variables
    $templater->register('my_array', $my_array);
    $templatevalues['my_insertvar'] = $templater->render(); // Save the template into a variable, "note that the data needs to be saved into an array a simple variable will throw an error"
    vB_Template::preRegister('FORUMHOME', $templatevalues);  // "insert" your variable into the FORUMHOME template
    

    然后您可以在 FORUMHOME 模板中使用该行添加新模板:

    {vb:raw my_insertvar}
    

    【讨论】:

    • 我知道这篇文章,但没有注意到它也包含现有模板。但我无法查看代码块。你能把它复制到这里吗?
    【解决方案2】:

    我只是纠结这个太久了……那个例子太糟糕了。不是尼亚克的错。感觉原作者对如何将简单的变量注册到现有的模板不是很清楚。

    我将上面的示例复制/粘贴到插件中,将 $my_var 设置为“test”,FORUMHOME 模板中的 {vb:raw my_insertvar} 不起作用。这是我最初尝试的代码:

    $my_var = "test";
    
    $templater = vB_Template::create('mytemplate'); // Define a template
    $templater->register('my_var', $my_var); // define some variables
    $templatevalues['my_insertvar'] = $templater->render();
    vB_Template::preRegister('FORUMHOME', $templatevalues);
    

    如果有人知道我在原始示例中无法访问 my_var 的值做错了什么,请告诉我!我不能让它为我的生活工作。它一直在吐出<!-- BEGIN TEMPLATE: mytemplate --><!-- END TEMPLATE: mytemplate -->

    ================================ 工作示例 ============== =================

    然后,我找到了一个更好的例子。事实证明,您只需要两行代码即可:

    1. 转到Plugins & Products > Plugin Manager
    2. 滚动到底部,然后单击[Add New Plugin]
    3. 我选择的钩子是global_bootstrap_init_start
    4. 插入以下两行(navbar 是我注册testVar_output 的模板):

      $testVar = "This is a test.";
      
      vB_Template::preRegister('navbar',array('testVar_output' => $testVar));
      
    5. 将此代码放入navbar

      {vb:raw testVar_output}

    6. 请注意,vb:raw 变量名称是array()LEFT 上的值。
    7. 似乎没有必要使用$templater->render() 函数来预注册变量,尽管我看到的所有示例都表明您需要它。只需注册变量,然后使用变量!就是这么简单!
    8. 我意识到这不允许模板缓存,这就是为什么我如此担心我无法让原始示例正常工作...(帮助!?)

    【讨论】:

    • 我只能假设navbar是一个内置模板,它被缓存了,这个变量会和它一起被缓存,所以不需要创建我自己的模板然后缓存它。 ..这是一个错误的假设吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 2015-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多