Questions tagged [conditional]

Conditional will perform different actions depending on some condition.

Filter by
Sorted by
Tagged with
34
votes
11answers
48k views

How can I add a dynamic "active" CSS class to the navigation on any given page?

Just wondering how people approach setting a class of current in their navigation. Is there anything in Craft or Twig where you can set a conditional to check if a page is the current page. Or do you ...
4
votes
2answers
948 views

Identify immediate siblings block type in matrix

I have a type of content that i use on the homepage of a site I am building, the code is shown here: <ul> {% for point in entry.keyPoints %} <li> <div class="a-...
5
votes
1answer
668 views

From a template, how can you order entries by one field, and if that field is empty a different field?

Is it possible to put conditions on the ordering of a loop of entries? I have two fields: title and alphaTitle. I want to order alphabetically, by alphaTitle if it has a value, otherwise by title. ...
1
vote
1answer
834 views

For loop, if statement, then limit

I've created two global variables which my content creator is going to use to turn off a bunch of articles and turn on a bunch more which a slight change in the Global. I have a page where there is a ...
6
votes
2answers
6k views

How do I use divisibleby() in a for loop to display two columns?

I try to write a row in which there are two columns: <div class="row"> <div class="block_txt"></div> <div class="block_txt"></div> </div> <div class="row"&...
2
votes
1answer
698 views

Return entries with startDate or endDate within a calendar year

I have two date fields in my entry and I want to return those entries with either a start date OR and end date within a calendar year. I can get those with a startDate within the calendar year using: ...
3
votes
3answers
334 views

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 %} ...
2
votes
2answers
297 views

If YouTube in Redactor Then Wrap in Div

So I have been using this CSS Tricks responsive video trick for years. The problem I'm having is that this new Craft site I built imported data over from EE into a single Redactor field. Is there any ...
2
votes
1answer
602 views

Detect if a language is translated or not

For entries where the content isn't translated yet I'd like to add a "Sorry not translated yet" message. Since all the content is synced is there a way to check if the synced content is the same as ...
7
votes
1answer
919 views

Using an IF-statement to define the Entry URL Format

Within a channel I have two kinds of possible article types, which I separate with the entry type feature. For the entry URL format I want to include the type, but only for one of the two. I've tried ...