Conditional will perform different actions depending on some condition.
Questions tagged [conditional]
137 questions
7
votes
1 answer
Conditionally Display Content if Section
How can I conditionally display content if its a specific section?
Currently I'm trying this with no luck:
{% if entry.section == 'lettings' %}{{ entry.rentFrequency.label }}{% endif %}
Niall Thompson
- 1,199
- 1
- 11
- 24
6
votes
1 answer
Is Shorter Twig Conditional possible?
Is there a way in Twig to make this conditional shorter so I don't use "craft.request.getSegment(2)" twice?
{% if craft.request.getSegment(2) == "knowledge" or
craft.request.getSegment(2) == "search" %}
Anna_MediaGirl
- 2,503
- 2
- 17
- 45
5
votes
2 answers
Correct code for a conditional field?
What's the correct way to create a conditional so that a field won't display if it's empty? Is it:
{% if entry.myentry | length %}
...
{% endif %}
or
{% if entry.myentry %}
...
{% endif %}
I tried both and both seem to work, but I want…
MDLG
- 165
- 1
- 2
- 8
3
votes
3 answers
Conditional Parsing Issues
I'm not sure what's wrong with this original markup:
Conditional One (doesn't work)
{% if entry.metaTitle is defined %}
{{ entry.metaTitle }}
{% elseif title is defined %}
{{ title }}
{% else %}
{{ siteName }}
{% endif %}
This works but seems…
Mark Busnelli Jr
- 926
- 7
- 18
3
votes
3 answers
Problem with IF conditional not working
I have 2 sections, events and activities, that share many fields. But activities doesn't have an eventLevel field as there isn't a level. eventLevel is a radio fieldtype. So I want to insert the eventLevel when it exists and if it doesn't just…
Paul Frost
- 1,060
- 10
- 23
2
votes
1 answer
Check if page is Search, use different classes
I'm looking for a shorter way of writing this check. If the user visits the search page, apply the 3 column to the search-block, else use the 5 column:
{% set currentPage = 'search' %}
{% if currentPage == "search" %}
{% for project in…
TRIM
- 314
- 2
- 9
2
votes
1 answer
Is there a way to check if any fields in a global set have content?
I have a global set called socialNetworkContent.
Is there a way to setup a conditional to check whether any of the fields within this set have content?
So the section wouldn't display if all the fields were blank.
Something along these lines:
{% if…
Niall Thompson
- 1,199
- 1
- 11
- 24
2
votes
1 answer
Plain Text Length Conditional
Wondering how to write a conditional that was dependent on the length of a plain text field within a matrix field. I have something like:
{% for block in entry.pricing %}
{% if block.destination|length > 25 %}TEST{% endif %}{{…
simonsweeney
- 399
- 3
- 9
2
votes
2 answers
Conditions in an if statement 'or'
I'm trying to do something like this for all the SEO meta info in my head
{% if entry or category is defined %}
...
{% endif %}
What's the right way to code this?
The reason for this is I have archive pages which won't be using some the meta…
sarah3585
- 899
- 7
- 14
1
vote
1 answer
Date specific conditional
Hi I'm trying to template out a simple conditional that shows content if the date set in a date field is greater or equal to today, and I can't seem to get the syntax quite right.
I have tried this:
{% if entry.promoEndDate|date ('>= ' ~ now) %}
…
since1976
- 249
- 2
- 6
1
vote
1 answer
showing content conditionally in layout
I'm trying to conditionally show some content inside the layout file. In my entries I have a lightswitch field - to indicate which entries should be excluded. This all works fine when I can identify the entry. But on the homepage it's not able to…
glider
- 647
- 3
- 13
1
vote
1 answer
Does Craft parse requests inside a conditional if it is false?
Does Craft parse the contents of a false/negative/empty conditional statement? So would you take a performance hit if you had a big chunk of code inside a conditonal that was false?
{% set foo = "foo" %}
{% if foo == foo %}Small code {% else %}…
Mark
- 731
- 3
- 11
1
vote
1 answer
How do I show something only for a parent segment and not it's children?
How do I display something only for one of the parent Structure sections and not others or this sections children?
I was thinking of using
{% if craft.request.segment(2) == 'modules' and craft.request.lastSegment|length %}''
but that still shows…
julzmon
- 941
- 2
- 9
- 19