first item from foreach loop from cgsi_getimages

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Sendlingur
Forum Members
Forum Members
Posts: 62
Joined: Wed Aug 08, 2018 4:59 pm

first item from foreach loop from cgsi_getimages

Post 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?
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: first item from foreach loop from cgsi_getimages

Post 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
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1609
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: first item from foreach loop from cgsi_getimages

Post by DIGI3 »

If you know it's always the first image, you can use

Code: Select all

{$imageinfo[0].src}
Not getting the answer you need? CMSMS support options
Locked

Return to “Modules/Add-Ons”