简体   繁体   中英

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.

If you need to print some text from language file to 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 .

Now follow to below step:

1. Language file

asign value in language file

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

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

2. Controller file

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

Print variable in twig file

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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