2

I'm looking for a shorter way of writing this check. If the user visits the search page, apply the 3 column to the search-block, else use the 5 column:

{% set currentPage = 'search' %}
{% if currentPage == "search" %}
   {% for project in pageEntries %}
      {% include '_partials/search-block' with {
         extraClasses: '3col'                    
         } 
      %}
   {% endfor %}
{% else %}
   {% for project in pageEntries %}
      {% include '_partials/search-block' with {
         extraClasses: '5col'                    
         } 
      %}
   {% endfor %}
{% endif %}
1
{% set class = (currentPage == "search")? '5col' : '3col' %} 
{% for project in pageEntries %}
     {% include '_partials/search-block' with { 
        extraClasses: class
     } %} 
{% endfor %}
1
  • Nice. You set a var, check for the "search page", implement 5col else use 3col. pass the var to "extraClasses". Thank you @robin
    – TRIM
    May 10 '18 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.