When to use "if" or "without"? When is it advisable or prudent to use without rather than a conditional statement to exclude something, eg a set of entries, based on one parameter?

For example, say I have real towns and fictional Towns that are listed on a related Regional page. These Towns are sorted real/fictional by a toggle field -- 0 for real, 1 for fictional.

The fictional towns are used elsewhere and should not be listed on any Regional page. In this case, should I be using if (see below) or without?

Here is how I am doing it right now in my Regional template:

{% if town.townFictional == 0 %}
    &lt;li&gt;{{town.link}}&lt;/li&gt;
{% endif %}


This is working fine, but I came across this question where using without was suggested.

Is without preferred in my case, and if so how do I use it? Here is my towns variable:

{% set towns = craft.entries.section('towns').relatedTo(counties) %}
For your example, you should exclude the fictional towns in the initial query itself rather than filtering them out afterwards:

{% set towns = craft.entries.section('towns').townFictional('not 1').relatedTo(counties) %}


So that no towns with the Fictional Lightswitch on will be returned from the database at all.

You would use the |without filter, if you already had an array of items and you wanted to filter some of them out while looping over them. This works best with arrays of simple primitives, such as an array of entry IDs, rather than whole objects.

You would be more likely to use an {% if %} tag if you still wanted to fetch the entry, but wanted to adjust some part of your output based on a condition. So for example if you had an array of entries from different sections, and they might not all have URLs, you might decide to output a link or just the title:

{% for entry in entries %}
    {% if entry.getUrl() %}
        &lt;li&gt;&lt;a href="{{ entry.getUrl()"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
    {% else %}
        &lt;li&gt;{{ entry.title }}&lt;/li&gt;
    {% endif %}
{% endfor %}