It's my first website using Craft.
I'm trying to figure out how to loop Matrix. I have created a field called bannerMatrix
with a block type called banner
that has 3 fields:
- Image (assets)
- Heading (plain text)
- Subheading (plain text)
This is what I have so far:
{% for block in entry.bannerMatrix %}
{% if block.type == "banner" %}
<div>
<img src="{{ block.image }}" alt="{{ image.title }}">
<div class="hero_msg">
<h3>{{ block.heading }}</h3>
<h4>{{ block.subheading }}</h4>
</div>
</div>
{% endif %}
{% endfor %}
Anything will be helpful. Thanks!
UPDATE
@JamieWade, thanks a lot for the super fast answer! Unfortunately, the code above still doesnt work for me :(
{% for block in entry.bannerMatrix %}
<div>
<img src="{{ block.image.first().title }}" alt="">
<div class="hero_msg">
<h3>{{ block.heading }}</h3>
<h4>{{ block.subheading }}</h4>
</div>
</div>
{% endfor %}
I also tried this :
{% set image = block.image.first() %}
{% if image %}
<img src="{{ image.getUrl('image') }}">
{% endif %}
And I dont get anything as well :(
I wonder if my structure is correct. So I attached a screenshot.
@Alec, yes there is content in the entry(I attached a screenshot). Now I'm even more curious, what's missing here. I also added the path to subfolder in the Field Setting.
{% else %}
just before the closing{% endfor %}
and put some text between, do you see the text?