Page 1 of 1

first item from foreach loop from cgsi_getimages

Posted: Tue Mar 12, 2019 4:07 pm
by Sendlingur
I'm using the
cgsi_getimages
to access images from content. (see codeblock below)

I only want to use the first image from the array, I have tried to use "{$image.src.0}" ,
"{$image.src.[0]}" ,
"{$image.src.first}", etc. without any luck.


This is the loop I'm using:

Code: Select all

       {if !empty($entry->fields)}

{cgsi_getimages assign='imageinfo' nocontent=1}{$entry->content}{/cgsi_getimages}

{foreach from=$imageinfo item=image}
 <img src="{$image.src}" class="text-left img-responsive" alt="Exhibition">
{/foreach}


{else}

........

Can someone explain to me how I can access only one image from the content with this loop?

Re: first item from foreach loop from cgsi_getimages

Posted: Tue Mar 12, 2019 9:33 pm
by Rolf
There are multiple ways to do this, but I prefer to use a simple counter and a break tag like used here http://cms.ms/mMW2

Re: first item from foreach loop from cgsi_getimages

Posted: Tue Mar 12, 2019 9:41 pm
by DIGI3
If you know it's always the first image, you can use

Code: Select all

{$imageinfo[0].src}