sundsx
sundsx

Reputation: 618

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.

Upvotes: 3

Views: 2741

Answers (2)

code stackflow
code stackflow

Reputation: 91

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>

Upvotes: 2

K. B.
K. B.

Reputation: 1430

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';

Upvotes: 3

Related Questions