score:3

Accepted answer

The attribute function does this, it can be used to access a "dynamic" attribute of a variable:

<table>
   {% for user in users %}
      <tr>
         {% for field in fields %}
            <td>{{ attribute(user,field) }}</td>
         {% endfor %}   
      </tr>
   {% endfor %} 
</table>

So the correct syntax is {{ attribute(user,field) }}, read the documentation here

score:0

If the user has one-to-many relationship with field (i.e. one user can have multiple fields), and it's defined as such in ORM mapping and in the entities (i.e. the User entity has a getFields() method, which returns a collection of Field entities), then you can do this:

<table>
   {% for user in users %}
      <tr>
         {% for field in user.fields %}
            <td>{{ field }}</td>
         {% endfor %}   
      </tr>
   {% endfor %} 
</table>

But if that's not the case, then it might help to describe a little bit more about what kind of relationship a User has with its fields.


Related Query

More Query from same tag