2017-10-24 1 views
0

Twig에 다시 작성 기능이 작동하지 않습니다. 뭐가 잘못 되었 니?PHP 변수가 Twig로 다시 작성됩니다.

PHP 소스 :

<?php foreach ($datas as $data) { ?> 
      <?php if ($data['information_id'] == $info_id) { ?> 
       <a href="<?php echo $data['href']; ?>" class="list-group active"><?php echo $data['title']; ?></a>    
      <?php } else { ?> 
      <a href="<?php echo $data['href']; ?>" class="list-group"><?php echo $data['title']; ?></a> 
      <?php } ?> 
      <?php } ?> 

재 작성 나뭇 가지에 :

{% for datas in data %} 
      {% if {{ attribute(data,information_id) }} == info_id %} 
      <a href="{{ data.href }}" class="list-group active">{{ data.title }}</a> 
      {% else %} 
      <a href="{{ data.href }}" class="list-group">{{ data.title }}</a> 
      {% endif %}   
     {% endfor %} 
+0

자세한 내용을 입력하십시오. 예를 들어 지금까지 무엇을 시도 했습니까? https://stackoverflow.com/help/how-to-ask – Cleared

+1

'{{data.information_id}}'/'{{data [ 'information_id']}}'/'{{attribute (data, information_id)}}' – DarkBee

답변

2

시도 :

{% for data in datas %} 
     {% if attribute(data,information_id) == info_id %} 
      <a href="{{ data.href }}" class="list-group active">{{ data.title }}</a> 
     {% else %} 
      <a href="{{ data.href }}" class="list-group">{{ data.title }}</a> 
     {% endif %}   
{% endfor %} 
당신이로 출력 할 때 당신은 {{ }}에서 변수를 포장 할 필요가

페이지. {% if %} 문 중간에 없습니다.

또한 {% for datas in data %}{% for data in datas %}으로 바 꾸었습니다. 나는 datas이 배열이라고 가정하고 data은 각각의 개별 항목입니다.

https://twig.symfony.com/doc/2.x/tags/for.html

관련 문제