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

opencart 3 how to Custom variable in twig page

我想显示来自语言模板中变量的自定义文本。

所以我声明了一个变量:

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

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

然后尝试在

中打印该变量
catalog/theme/mytheme/template/common/menu.twig

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

但什么也没发生。

你能解释一下如何实现吗?非常感谢

...我发现 twig 与 angulajs 有很多相似之处。

如果您需要将一些文本从语言文件打印到 TWIG

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

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

您的语言文件应放在相应的文件夹中...在本例中为:

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

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

第一件事是错误的。 您不能在 admin 中分配语言变量并在 catalog 中使用。

现在执行以下步骤:

1.语言文件

在语言文件中赋值

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

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

2。控制器文件

在您要使用语言变量的控制器中调用语言文件

catalog\controller\common\your_controller_file.php 

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

3。树枝文件

在 twig 文件中打印变量

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

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