2

I'm in the context of an Entry that has a Matrix field, and one of those Matrix fields is a Dropdown called subsection. I want to grab all Matrix blocks that have subsection set to 'intro'.

This is how I'm trying to do it and it definitely doesn't work. Is there another way to accomplish this?

{% for block in entry.myMatrix.subsection('intro') %}
…
{% endfor %}
3

How about:

{% for block in entry.myMatrix if block.subsection == 'intro' %}
    ...
{% endfor %}
|improve this answer|||||
  • This displays an error for me: "Internal Server Error Craft\MatrixBlockModel and its behaviors do not have a method or closure named "subsection"." – cmal Jul 12 '14 at 16:55
  • Can you post a screenshot of your Matrix field? I just want to make sure I'm visualizing it correctly. – Tyler Willingham Jul 12 '14 at 17:19
  • Tyler: Here is a screenshot. I made some of the names more generic than my actual case (obviously I don't call my Matrixes "myMatrix"!) but the scenario is still the same. More realistic code based on this screenshot would be {% for block in entry.approachBlurb if block.subsection('team') %} – cmal Jul 12 '14 at 17:45
  • I replicated your setup and tested against block.subsection == 'research'. I updated my answer with a functioning conditional :) Let me know if this still doesn't work for you. – Tyler Willingham Jul 12 '14 at 18:09

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.