php - Get key name of array value in twig for loop -


i'm trying have twig output key name(column name mysql data). want basicly: <a class="listquestions" href="#" id="{{ key }}"...

current codebase:

<table id="listquestions" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%"> <thead>     <tr>         {% key, answer in answers[0] %}             <th>{{ key }}</th>         {% endfor %}     </tr> </thead> <tbody>      {% key,answer in answers %}         <tr>             <td>{{ answer.a_id }}</td>             <td>                 <a class="listquestions" href="#" data-name="a_text" data-type="text" data-pk="{{ answer.a_id }}" data-url="{{ path_for('qa.edit') }}" data-title="enter attribute name">                     {{ answer.a_text }}                 </a>             </td>             <td>                 <a class="listquestions" href="#" data-name="a_attribute_name" data-type="text" data-pk="{{ answer.a_id }}" data-url="{{ path_for('qa.edit') }}" data-title="enter attribute name">                     {{ answer.a_attribute_name}}                 </a>             </td>         </tr>     {% endfor %} </tbody> 

php function var_export($data,true) outputs:

array (   0 =>    array (     'a_id' => '1',     'a_text' => 'text',     'a_attribute_name' => 'attr',   ),   1 =>    array (     'a_id' => '2',     'a_text' => 'text',     'a_attribute_name' => 'attr',   ),   2 =>    array (     'a_id' => '3',     'a_text' => 'text',     'a_attribute_name' => 'attr',   ), ) 

i tried adding twigextension key($answer.a_text) key() not work twig for-loops.

so missing? can output key name inside <thead> see i'd second for-loop.

<table id="listquestions" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%"> <thead>     <tr>         {% key, answer in answers[0] %}             <th>{{ key }}</th>         {% endfor %}     </tr> </thead> <tbody>      {% key,answer in answers %}         {% field, value in answer %}         <tr>            {% if field == 'a_id' %}             <td>{{ answer.a_id }}</td>             {% else %}             <td>                 <a class="listquestions" href="#" data-name="{{ field }}" data-type="text" data-pk="{{ answer.a_id }}" data-url="path_for('qa.edit')" data-title="enter attribute name">                     {{ value }}                 </a>             </td>             {% endif %}         </tr>         {% endfor %}     {% endfor %} </tbody> </table> 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -