1

Is it possible to control if some content shows that's within a Matrix field if a lightswitch field on the entry is false.

I expect not as you're inside the matrix loop.

{% for block in entry.section3 %}
 ...
{% if block.applyButton %}
 ...
   {% if entry.applicationsClosed('not 1') %}
    {% for asset in entry.applyButtonDocument %}
     <a href="{{ asset.getUrl() }}" class="button button--black">apply</a>
    {% endfor %}
   {% endif %}
...
{% endif %} 
....
{% endfor %}        

I don't want to put the lightswitch within the Matrix as that would put it in an illogical place and would be needed to be switched multiple times.

It's being used as more of a global setting across the page to change various bits of content.

3

You can definitely access and use fields on the entry you're viewing within a matrix field loop. The only thing you need to watch out for is repeating the entry variable in your for loop.

You can simplify your if statement slightly by using {% if not entry.applicationsClosed %}

  • I ended up using {% set applicationsClosed = entry.applicationsClosed %} and then it was all good. By your answer it looks like I messed up the loop, so I will see if I can sort that out. Many thanks. – sarah3585 Sep 1 '16 at 8:40

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.