[英]Codeigniter TWIG: How to access global variable in template
如何訪問.twig模板中的模型函數?
{% if($this->my_model->my_function("123")) %}
Hello World
{% endif %}
這將返回Unexpected character "$"
編輯:
我意識到我可以做這樣的事情
$this->twig->addGlobal("my_function", $this->my_model->my_function("123") ? true : false)
但是考慮到123
可以是任何東西,我不知道如何允許輸入參數。
將模型添加為全局變量而不是函數:
$this->twig->addGlobal("my_model", $this->my_model);
然后,您可以在Twig中進行操作( "123"
可以是任何值):
{% if my_model.my_function("123") %}
Hello World
{% endif %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.