Skip to main content

Questions tagged [conditional]

Conditional will perform different actions depending on some condition.

Filter by
Sorted by
Tagged with
35 votes
11 answers

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 ...
Gareth's user avatar
  • 1,605
4 votes
2 answers

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-...
Christopher Healey's user avatar
5 votes
1 answer

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. ...
Becky Soll's user avatar
1 vote
1 answer

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 ...
afc's user avatar
  • 67
7 votes
1 answer

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 ...
rppld's user avatar
  • 336
6 votes
2 answers

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"&...
KSPR's user avatar
  • 3,786
3 votes
2 answers

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 ...
Mark Busnelli Jr's user avatar
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 %} ...
Mark Busnelli Jr's user avatar
2 votes
1 answer

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 ...
KSPR's user avatar
  • 3,786
2 votes
1 answer

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: ...
Clive Portman's user avatar