<p>The Super Table field value is a query, so the <code>.all()</code> needs to be called on the field itself (not on <code>lightswitch</code>). But looping over queries is in itself deprecated in Craft, so you should set it to a variable first, and then loop over that.</p>

<p>In any case, the <code>.all()</code> will return all <em>rows</em> of your Super Table field, each of which contains your lightswitch field (even if there is only one row).</p>

<p>If you know there is only one row, perhaps something like this would work, but I haven't tested it:</p>

<pre><code>{% if craft.products.supertable.one().lightswitch == 1 %}
</code></pre>

<p>I would anyways recommend performing the query first, then use the result to loop or get your field.</p>

CC BY-SA 4.0
2019-12-18T12:02:32.853Z
2019-12-18T12:02:32.853Z
KSP
<p>Is it possible to check for a value in a supertable field during the for loop:</p>

<pre><code>{% for item in craft.products.supertable.lightswitch(1).all() %}
  {# stuff #}
{% endfor %}
</code></pre>

<p>This returns </p>

<blockquote>
  <p>Impossible to invoke a method ("lightswitch") on a null variable.</p>
</blockquote>

<p>So I guess the content of the supertable field is not available yet?
Because if I write:</p>

<pre><code>{% for item in craft.products.all() %}
  {% if item.supertable.lightswitch == 1 %}
    {# stuff #}
  {% endif %}
{% endfor %}
</code></pre>

<p>This works nicely. Is this not a part of the element criteria model?</p>

<elementcriteriamodel><plugin-supertable>
Check for value in supertable
# Check for value in supertable

(Asked by: username_0 on 2019-12-18)

Is it possible to check for a value in a supertable field during the for loop:
{% for item in craft.products.supertable.lightswitch(1).all() %}
  {# stuff #}
{% endfor %}

This returns 

Impossible to invoke a method ("lightswitch") on a null variable.

So I guess the content of the supertable field is not available yet?
Because if I write:
{% for item in craft.products.all() %}
  {% if item.supertable.lightswitch == 1 %}
    {# stuff #}
  {% endif %}
{% endfor %}

This works nicely. Is this not a part of the element criteria model?

**Tags:** elementcriteriamodel, plugin-supertable


---

## 1 answers

### Answer by username_1 on 2019-12-18. Score: 1 | Accepted answer

The Super Table field value is a query, so the .all() needs to be called on the field itself (not on lightswitch). But looping over queries is in itself deprecated in Craft, so you should set it to a variable first, and then loop over that.
In any case, the .all() will return all rows of your Super Table field, each of which contains your lightswitch field (even if there is only one row).
If you know there is only one row, perhaps something like this would work, but I haven't tested it:
{% if craft.products.supertable.one().lightswitch == 1 %}

I would anyways recommend performing the query first, then use the result to loop or get your field.


---

