I'm new to all this. Is it possible to use craft.entries
to return all entries with an empty entries field? Something like:
{% set drinksWithNoIngredients = craft.entries.section("drinks").ingredients(":empty:") %}
{% for drink in drinksWithNoIngredients %}
<p>Do something with {{ drink.title }}...</p>
where ingredients
is an entries field handle. This doesn't seem to work on entries fields, though. Or maybe I could do some kind of relatedTo
magic, where the targetElement
is some kind of special null value?
An alternative seems to be this:
{% set drinksWithNoIngredients = craft.entries.section("drinks") %}
{% for drink in drinksWithNoIngredients %}
{% if not drink.ingredients.total() %}
<p>Do something with {{ drink.title }}...</p>
But doing it that way calls .total()
on every drink. Is that going to cause performance problems if I have a lot of drinks?