CMS Development

jestlinbaum
参加者

Get first value of repeater field in blog listing

解決

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 いいね!
1件の承認済みベストアンサー
stefen
解決策
キーアドバイザー | Solutions Partner
キーアドバイザー | Solutions Partner

Get first value of repeater field in blog listing

解決

@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

元の投稿で解決策を見る

1件の返信
stefen
解決策
キーアドバイザー | Solutions Partner
キーアドバイザー | Solutions Partner

Get first value of repeater field in blog listing

解決

@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