Condition
{% if %}Shows or hides content based on an expression.The Condition block wraps other blocks and shows them only if an expression evaluates to true. If the expression fails, the content is hidden entirely.
{% if post.thumbnail %}
<img src="{{ post.thumbnail.src }}" alt="{{ post.thumbnail.alt }}">
{% endif %}
Writing conditions
A condition is any expression that returns true or false:
{% if post.thumbnail %} {# exists? #}
{% if user.logged_in %} {# boolean #}
{% if post.category.slug == 'featured' %} {# comparison #}
{% if user.logged_in and user.role == 'editor' %} {# combined #}
{% if not post.password_required %} {# negation #}
{% if 'featured' in post.tags %} {# contains #}
For the full list of operators (comparison, logical, containment, math), see the Syntax reference.
Handling the false case
There is no {% else %} in Condition blocks. To handle both cases, use two Condition blocks with opposite expressions:
{% if post.excerpt %}
<p class="excerpt">{{ post.excerpt }}</p>
{% endif %}
{% if not post.excerpt %}
<p class="excerpt">{{ post.content|truncate(150) }}</p>
{% endif %}
Common mistake
Because there is no else, it's easy to forget the opposite case. Your visitors will see nothing when the condition is false — no fallback, no placeholder, just blank space. Always ask yourself: "What should show when this is false?"
Common patterns
Logged-in vs guest
{% if user.logged_in %}
<p>Welcome back, {{ user.display_name }}!</p>
{% endif %}
{% if not user.logged_in %}
<p><a href="/login">Log in</a> to access more features.</p>
{% endif %}
Thumbnail with fallback
{% if post.thumbnail %}
<img src="{{ post.thumbnail.src('large') }}" alt="{{ post.title }}">
{% endif %}
{% if not post.thumbnail %}
<img src="/default-image.jpg" alt="">
{% endif %}
Badge based on category
{% if post.category.slug == 'featured' %}
<span class="badge">Featured</span>
{% endif %}
Next steps
- Loop — repeat content over collections
- Dynamic Data — all available fields you can check against
- Syntax — full expression and operator reference