Get first value of repeater field in blog listing

SOLVE
jestlinbaum
Participant

I am making a gallery/our work page using a blog. Each post is a small paragraph and then a bunch of images.

 

I made a custom module to edit each post, a repeater group consisting of an image field and a caption field.

 

 

{% for item in module.sign_image %}
<div class="image-wrap">
  <div class="img-hold">
  
{% if item.image.src %} {% set sizeAttrs = 'width="{{ item.image.width }}" height="{{ item.image.height }}"' %} {% if item.image.size_type == 'auto' %} {% set sizeAttrs = 'style="max-width: 100%; height: auto;"' %} {% elif item.image.size_type == 'auto_custom_max' %} {% set sizeAttrs = 'width="100%" height="auto" style="max-width: {{ item.image.max_width }}px; max-height: {{ item.image.max_height }}px"' %} {% endif %} <img src="{{ item.image.src }}" alt="{{ item.image.alt }}" {{ sizeAttrs }}> {% endif %} </div> {% if item.caption %} <div class="cap-hold"> {% inline_text field="caption" value="{{ item.caption }}" %} </div> {% endif %}

 

 

This is working fine.

 

In the listing template I would like to display just the image (without the caption) from the first group. Is this possible?

0 Upvotes
1 Accepted solution

Accepted Solutions
stefen
Solution
Key Advisor | Partner

@jestlinbaum inside of your for loop you can reference the "loop" variable to check what iteration you're in. To check for the first loop you can use the following if statement:

{% for item in mysequence %}

{% if loop.first %}
I'll only print to the page on the first loop!
{% endif %}

{% endfor %}
Stefen Phelps, Community Champion, Kelp Web Developer

View solution in original post

1 Reply 1
stefen
Solution
Key Advisor | Partner

@jestlinbaum inside of your for loop you can reference the "loop" variable to check what iteration you're in. To check for the first loop you can use the following if statement:

{% for item in mysequence %}

{% if loop.first %}
I'll only print to the page on the first loop!
{% endif %}

{% endfor %}
Stefen Phelps, Community Champion, Kelp Web Developer

View solution in original post