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" %}
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityIs 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" %}
The Containment Operator helps with this...
It returns true if the left operand is contained in the right
{% if craft.request.getSegment(2) in ['knowledge', 'search'] %}
OR
{% if craft.request.getSegment(2) not in ['', 'sale'] %}