I have 1 Matrix field: contentBlock
With 2 Block types: text photo
With nested fields: text -> text photo -> photo
My attempt at using if statements, which didn't work, to toggle between text and photo looks like the following:
{% for block in entry.contentBlock %}
{% if block.type == 'text' %}
{{ block.text }}
{% endif %}
{% elseif block.type == 'image' %}
{% set image = block.image.first() %}
{% if image %}
<img src="{{ image.getUrl('thumb') }}" alt="{{ image.title }}">
{% endif %}
{% endfor %}
Would using {% switch %} be a better method, or was I close to correct using the if statements? I think getting the hang of this will open up the true posibilities of using Craft Matrix fields.
Thank you for any input on this question.