简体   繁体   English

opencart 3如何在树枝页面中自定义变量

[英]opencart 3 how to Custom variable in twig page

i want to show custom text come from a variable in language template. 我想显示自定义文本来自语言模板中的变量。

so i declared a variable in: 所以我在以下位置声明了一个变量:

admin/language/en-gb/extension/theme/mytheme.php

$_['text_label_menu_count']  = 'Some count';

and then try to print that variable in 然后尝试在中打印该变量

catalog/theme/mytheme/template/common/menu.twig

<h4 class="text-white"> {{ text_label_menu_count }} </h4>

but nothing happens. 但什么也没发生。

Can you explain me how to achieve this? 您能解释一下如何实现吗? Thanks a lot 非常感谢

... I found a lot of twig similarities with angulajs. ...我发现与angulajs有很多相似之处。

If you need to print some text from language file to TWIG 如果您需要将一些文本从语言文件打印到TWIG

      catalog/view/theme/your_template/template/common/menu.twig

<h4 class="text-white"> {{ text_label_menu_count }} </h4>

Your language file should be placed to the corresponding folder... in this case to: 您的语言文件应放置在相应的文件夹中...在这种情况下,请执行以下操作:

catalog/language/en-gb/common/menu.php

$_['text_label_menu_count']  = 'Some count';

First thing is wrong. 第一件事是错的。 You cannot asign language variable in admin and used in catalog . 您不能在admin分配语言变量,也不能在catalog使用它。

Now follow to below step: 现在,请按照以下步骤操作:

1. Language file 1.语言文件

asign value in language file 在语言文件中赋值

catalog\language\en-gb\common\your_language_file.php

$_['text_label_menu_count']  = 'Some count'; 

2. Controller file 2.控制器文件

call language file in controller where you would like to use language variable 调用控制器中要使用语言变量的语言文件

catalog\controller\common\your_controller_file.php 

$this->load->language('common/your_language_file');

3. Twig file 3.树枝文件

Print variable in twig file 在树枝文件中打印变量

catalog\view\theme\default\template\common\your_view_file.twig

<h4 class="text-white"> {{ text_label_menu_count }} </h4>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM