I made a module that executes a query and shows the result in a page, the query is executed correctly, but the result is not shown in the template.
I know that the query is executed correctly because I used var_dump()
to verify that.
This is the code in the controller.
public function ahcmembers() { $nums = array(); $query = Drupal::entityQuery('node') ->condition('type', 'member') ->condition('field_member_type', 'number') ->execute(); if (!empty($query)) { foreach ($query as $numId) { $num = Node::load($numId); $nums[] = $num; } } return array( '#theme' => 'ahcmembers', '#titulo' => $this->t('Members'), '#nums' => $nums, ); }
This is the code in the template:
<div> {% if nums %} {% for n in nums %} <div>{{ n.get('title').value }}</div> <div>{{ n.get('field_member_type').value }}</div> {% endfor %} {% endif %} </div>