Opencart php to twig


Opencart php to twig



can anybody help convert to twig this piece of code.


foreach ($methods as $method){?>
<li><a href="#tab-express<?php echo $method;?>" data-toggle="tab"><?php echo ${'tab_express' . $method}; ?></a></li>
<?php } ?>



I have tried this:


{% for method in methods %} <li><a href="#tab-express{{ method }}" data-toggle="tab">{{ 'tab_express' ~ method }}</a></li>
{% endfor %}



But this part: {{ 'tab_express' ~ method }} does not work. What wrong?


{{ 'tab_express' ~ method }}



*EDIT:
need retrieve names of the tabs from the controller


foreach ($data['methods'] as $method){
$data['tab_express' . $method] = $this->language->get('tab_express' . $method);
}



*
I answered below





Possible duplicate of Symfony2 - How to access dynamic variable names in twig
– DarkBee
Jul 2 at 13:57




1 Answer
1



solution for my question i found.
in controller should be:


foreach ($data['methods'] as $method){
$data['tab_express'][$method] = $this->language->get('tab_express' . $method);



Twig:


{% for method in methods %}
<li><a href="#tab-express{{ method }}" data-toggle="tab">{{ tab_express[method] }}</a> </li>
{% endfor %}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

JMeter fails on beanshell imports

Why in node-red my HTTP POST no receive payload from inject?

PHP contact form sending but not receiving emails