Answers.Body: <p>For anyone else having a similar problem, the solution was this:</p>
  
  <pre><code>    {% for module in entry.pageBuilder.all() %}
          {% do module.useMemoized(entry.pageBuilder) %}
      {% endfor %}
  
      {% for module in entry.pageBuilder.all() if module.level == 1 %}
          {% if module.type != 'moduleColumn' %}
              {% include '_partials/page-builder/_' ~ module.type %}
          {% endif %}
      {% endfor %}
  </code></pre>
  
  <p>and then inside <strong>_moduleRow.twig</strong></p>
  
  <pre><code>    &lt;div class="row flex flex-wrap"&gt;
          {% for module in module.children.all() %}
              {% if module.type == 'moduleColumn' %}
                  &lt;div class="md:w-1/{{module.width}} "&gt;
                  {% for module in module.children.all() %}
                      {% include '_partials/page-builder/_' ~ module.type %}
                  {% endfor %}
                  &lt;/div&gt;
              {% else %}
                  {% include '_partials/page-builder/_' ~ module.type %}
              {% endif %}
          {% endfor %}
      &lt;/div&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-13T01:08:48.593Z
Answers.LastActivityDate: 2020-01-13T01:08:48.593Z
Answers.UserDisplayName: Tyssen
Body: <p>I have a Neo field set up like so:</p>
  
  <pre><code>-Row
  --Column
  -Body
  </code></pre>
  
  <p>Columns can also contain <code>body</code>.</p>
  
  <p>With this:</p>
  
  <pre><code>{% set modules = entry.pageBuilder
          .with([
              'moduleBody',
              'moduleRow',
              'moduleColumn',
          ])
          .level(1)
          .all()
  %}
  
  {% for module in modules %}
      {% if module.type != 'moduleColumn' %}
          {% include '_partials/page-builder/_' ~ module.type %}
      {% endif %}
  {% endfor %}
  
  {% set moduleArray = [] %}
  
  {# Remove duplicate module types from array #}
  {% for moduleType in modules %}
      {% if moduleType.type not in moduleArray %}
          {% set moduleArray = moduleArray|merge([moduleType.type]) %}
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p><strong>_moduleBody.twig</strong></p>
  
  <pre><code>&lt;div class="module-body mb-8"&gt;
    {% if module.heading %}&lt;h2&gt;{{ module.heading }}&lt;/h2&gt;{% endif %}
    {{ module.body }}
  &lt;/div&gt;
  </code></pre>
  
  <p>I get <code>body</code> blocks output fine if they're not nested in a row/column.</p>
  
  <p><strong>_moduleRow.twig</strong></p>
  
  <pre><code>&lt;div class="row flex flex-wrap"&gt;
      {% set columns = module.children %}
      {% for column in columns %}
      &lt;div class="md:w-1/{{column.width}} "&gt;
      {% for item in column.children %}
          {% include '_partials/page-builder/_' ~ item.type %}
      {% endfor %}
      &lt;/div&gt;
      {% endfor %}
  &lt;/div&gt;
  </code></pre>
  
  <p>With the above, I get an error: </p>
  
  <blockquote>
    <p>Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.</p>
  </blockquote>
  
  <p>If I change <code>set columns = module.children</code> to <code>set columns = module.children.all()</code> I get the same thing. If I change it to</p>
  
  <pre><code>{% set columns = module.children
          .with(['moduleColumn'])
          .level(1)
          .all()
  %}
  </code></pre>
  
  <p>there's no error, but no output either (other than the HTML for the row which is outside the code for the column contents).</p>
  
  <p>What do I need to do to get the columns to output?</p>
  
  <p>I guess I'm also going to have a problem with <code>for item in column.children</code> because inside <code>moduleBody</code> it's calling <code>module.variable</code> not <code>item.variable</code> but if the outer loop uses module, I can't use it for the inner loop too.</p>
  
Tags: <plugin-neo>
Title: Neo: children won't display or I get all() deprecation notice
ThreadText: # Neo: children won't display or I get all() deprecation notice
  
  (Asked by: username_0 on 2019-12-23)
  
  I have a Neo field set up like so:
  
  ```
  -Row
  --Column
  -Body
  
  ```
  
  Columns can also contain `body`.
  
  With this:
  
  ```
  {% set modules = entry.pageBuilder
          .with([
              'moduleBody',
              'moduleRow',
              'moduleColumn',
          ])
          .level(1)
          .all()
  %}
  
  {% for module in modules %}
      {% if module.type != 'moduleColumn' %}
          {% include '_partials/page-builder/_' ~ module.type %}
      {% endif %}
  {% endfor %}
  
  {% set moduleArray = [] %}
  
  {# Remove duplicate module types from array #}
  {% for moduleType in modules %}
      {% if moduleType.type not in moduleArray %}
          {% set moduleArray = moduleArray|merge([moduleType.type]) %}
      {% endif %}
  {% endfor %}
  
  ```
  
  **\_moduleBody.twig**
  
  ```
  <div class="module-body mb-8">
    {% if module.heading %}<h2>{{ module.heading }}</h2>{% endif %}
    {{ module.body }}
  </div>
  
  ```
  
  I get `body` blocks output fine if they're not nested in a row/column.
  
  **\_moduleRow.twig**
  
  ```
  <div class="row flex flex-wrap">
      {% set columns = module.children %}
      {% for column in columns %}
      <div class="md:w-1/{{column.width}} ">
      {% for item in column.children %}
          {% include '_partials/page-builder/_' ~ item.type %}
      {% endfor %}
      </div>
      {% endfor %}
  </div>
  
  ```
  
  With the above, I get an error:
  
  > Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them.
  
  If I change `set columns = module.children` to `set columns = module.children.all()` I get the same thing. If I change it to
  
  ```
  {% set columns = module.children
          .with(['moduleColumn'])
          .level(1)
          .all()
  %}
  
  ```
  
  there's no error, but no output either (other than the HTML for the row which is outside the code for the column contents).
  
  What do I need to do to get the columns to output?
  
  I guess I'm also going to have a problem with `for item in column.children` because inside `moduleBody` it's calling `module.variable` not `item.variable` but if the outer loop uses module, I can't use it for the inner loop too.
  
  **Tags:** plugin-neo
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-01-13. Score: 2 | Accepted answer
  
  For anyone else having a similar problem, the solution was this:
  
  ```
      {% for module in entry.pageBuilder.all() %}
          {% do module.useMemoized(entry.pageBuilder) %}
      {% endfor %}
  
      {% for module in entry.pageBuilder.all() if module.level == 1 %}
          {% if module.type != 'moduleColumn' %}
              {% include '_partials/page-builder/_' ~ module.type %}
          {% endif %}
      {% endfor %}
  
  ```
  
  and then inside **\_moduleRow.twig**
  
  ```
      <div class="row flex flex-wrap">
          {% for module in module.children.all() %}
              {% if module.type == 'moduleColumn' %}
                  <div class="md:w-1/{{module.width}} ">
                  {% for module in module.children.all() %}
                      {% include '_partials/page-builder/_' ~ module.type %}
                  {% endfor %}
                  </div>
              {% else %}
                  {% include '_partials/page-builder/_' ~ module.type %}
              {% endif %}
          {% endfor %}
      </div>
  
  ```
  
  
  ---
  
  