B
B
bohdanNa2018-02-27 18:48:29
PHP
bohdanNa, 2018-02-27 18:48:29

How to convert to twig?

I just started getting acquainted with twig, but I already have a problem that I don’t know how to solve
How can I convert this code to twig?
The difficulty lies in${$setting_field.'_value'}

<td><?php echo ${'text_ym_filter_data_'.$setting_field}; ?></td>
<td>
  <select">
  <?php foreach(${$setting_field} as ${$setting_field.'_value'} => ${$setting_field.'_title'}){ ?>
    <?php if($filter_data_group_id == ${$setting_field.'_value'}){ ?>
      <option selected="" value="<?php echo ${$setting_field.'_value'}; ?>"><?php echo ${$setting_field.'_title'}; ?></option>
    <?php }else{ ?>
       <option value="<?php echo ${$setting_field.'_value'}; ?>"><?php echo ${$setting_field.'_title'}; ?></option>
    <?php } ?>
  <?php } ?>
  </select>
</td>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ivankomolin, 2018-02-27
@bohdanNa

Dynamic variables... When I see it, for some reason I cringe
. Tell me, is it really more convenient than arrays, for example?
And in twig, this can be written like this:

{% set var = setting_field~'_value' %}
{{ var }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question