M
M
martin_eden_msk2021-05-29 16:25:56
PHP
martin_eden_msk, 2021-05-29 16:25:56

Convert a piece of twig to regular php, how?

Good day to all!
There is a piece of code in the twig template that I can’t convert to normal PHP in any way.



{% for not_calculate in not_calculate_dpd %}
{% if not_calculate.value == attribute(_context, 'shipping_dpd_not_calculate' ~ not_calculate.value) %}
{{ not_calculate.name }}
{% else %}
{{ not_calculate.name }}
{ % endif %}
{% endfor %}


is only interested in the line: {% if not_calculate.value == attribute(_context, 'shipping_dpd_not_calculate' ~ not_calculate.value) %}

thanks for the help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2021-05-29
@delphinpro

foreach ($not_calculate_dpd as $not_calculate) {
  if ($not_calculate['value'] == attribute($_context, 'shipping_dpd_not_calculate' ~ $not_calculate['value'])) {
    echo $not_calculate['name'];
  } else {
    echo $not_calculate['name'];
  }
}

However, the condition is meaningless, so
foreach ($not_calculate_dpd as $not_calculate) {
  echo $not_calculate['name'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question