We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [logic]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
130 views

Building a filtering system using both OR and AND relations

I'm trying to set up a filtering system similar to the one found on the product pages on asos.com. That system has different category groups of filters, where selecting multiple filters inside a ...
2
votes
2answers
937 views

Division by zero error as a result of calculation

I have entries which contain a drop down list of items that I need to run calculations on. In my template, I am filtering the entries by the drop down field so I can get the sum total of the entries ...
1
vote
1answer
65 views

Reusing logic by setting different keywords to create new variables

I need to reuse logic for 15 entry groupings in a template. In my non DRY version, I simply changed one word in the variable name to create a new variable and although it works just fine, it's very ...
1
vote
1answer
935 views

Set a Variable inside a conditional

I'm building my first Craft site and need to set a variable if a field has an image and then use that variable elsewhere in the template. The field is part of a matrix and will repeat. What I have ...
2
votes
2answers
152 views

Are there any tradeoffs if you use the null-coalescing operator in place of first()?

With the addition of the null-coalescing operator (??) in Twig, it now appears that the following two examples both provide a way to retrieve the first entry and fallback to null if no entry exists: {...
1
vote
2answers
707 views

Conditional logic to add class for specific section entries

I'm trying to create a conditional logic so that the class 'white-nav-bg' is added to the element on the 'blog' section entries only. Below is the code I'm currently using to try and achieve this ...
2
votes
2answers
1k views

Conditional Logic to show or hide fields in the admin?

I'm looking for a way to show or hide fields when editing an entry based on items selected. I need to manage a list of businesses and my plan is to have a channel to hold them all. But based on the ...
3
votes
1answer
380 views

RelatedTo Query Using Both “and” and “or”

I'm attempting to build a filter that queries entries of a section based on two criteria: A selection of one or more categories (inclusive), and a single related entry (exclusive). Specifically, the ...
2
votes
1answer
620 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: ...
2
votes
1answer
85 views

How do I add a second section name to this logic?

I need to add a second section name to this code: craft.entries.section('not homePage') I can't figure out the correct formatting. I've tried: craft.entries.section('not homePage,clientPage') craft....