Questions tagged [switch]
The switch tag has no usage guidance.
10
questions
2
votes
1
answer
234
views
Loop through Matrix Block fields within a Switch Case and retain HTML structure
I'm struggling to get my head around the syntax to output information in a correct HTML structure. At the moment I have this:
{% for block in entry.menuBuilder %}
{% switch block.type %}
{% case '...
1
vote
1
answer
157
views
Craft 2: Serve language / locale i18n according to user agent
As the official documentation does not give any hints on this:
I am wondering how to serve the correct localization of my website according to the user’s language preference and/or browser/OS ...
1
vote
2
answers
254
views
Switch entry type based on the category
I'm trying to use different entry types for certain categories. My category group is called categories, and the slug for Features is features. I have the category group pointed to categories/_entry. ...
1
vote
1
answer
250
views
Creating a switch based on entry handle
I'm trying to create a switch statement for a single entry event template that has various entry fields associated with it (description, contact, location, etc.) from an Events Channel I have. Rather ...
1
vote
1
answer
185
views
Passing Matrix block to a macro
I want to fetch a specific block from a Matrix global then pass it through a macro which returns a response based on the block type. However, if I try to use slice the type doesn't appear to be ...
1
vote
2
answers
16k
views
Switch Twig condition Case with OR condition (two values in the case) [duplicate]
I got a Twig switch in a template like:
{% switch bodyClass %}
{% case 'A' %}
...
{% case 'B' %}
...
{% default %}
...
{% endswitch %}
I would like to add ...
1
vote
1
answer
544
views
Switch in a Macro
I'm getting the following error:
Unexpected end of template. Twig was looking for the following tags "case", "default", or "endswitch" to close the "switch" block started at line 11)
Here is the ...
2
votes
1
answer
238
views
How do you use a Matrix to toggle between multiple fields from multiple blocks?
I have 1 Matrix field:
contentBlock
With 2 Block types:
text
photo
With nested fields:
text -> text
photo -> photo
My attempt at using if statements, which didn't work, to toggle between text and ...
7
votes
1
answer
2k
views
"A" or "B" in switch statements?
Is it possible to provide different possible values per case?
I've tried the following formats without success.
{% case "A" or "B" or "C" %}
{# run this if case matches A or B or C #}
I saw this ...
1
vote
3
answers
243
views
Opening and closing table within a switch
Within my matrix I have two blocks: Day and Event. Day is just a date field while the event block has two text fields.
What's the best way to wrap the event data, which needs to show up as a table ...