• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: how to not display img tag if image don´t exists
PostPosted: Thu Mar 14, 2019 10:19 am 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 31
Im using this loop to loop through a huge database. It takes the content images and puts them in the <img> tag.

In most cases the image is still around and every thing works fine. But in some cases the image doesn't exist and the img url is broken and as a result it displays the no image icon.

the thing is that I'm not sure how to make the loop detect if there is an actual file behind the img url or if the file is missing.

I've tried to use
Quote:
empty, !empty, ==file, etc.
but obviously the loop is reading the broken urls as imgs.

below is the loop I'm using, can someone please advise me

Code:
     {cgsi_getimages assign='imageinfo' nocontent=1}{$entry->content}{/cgsi_getimages}
      {foreach from=$imageinfo[0].src item=image}
        {if empty($image)}
      <img src="uploads/images/img-01.jpg" class="sidebar-img" alt="{$entry->title}"/>
        {else}   
           <img src="{$image}" class="sidebar-img" alt="{$entry->title}">
        {/if}
      {/foreach}


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: how to not display img tag if image don´t exists  Topic is solved
PostPosted: Thu Mar 14, 2019 3:45 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Feb 25, 2009 4:25 am
Posts: 650
Location: Victoria, BC
I haven't tested, but you should be able to use {if file_exists($image)}
You may need to enable permissive smarty in your config file.

_________________
Not getting the answer you need? CMSMS support options


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: how to not display img tag if image don´t exists
PostPosted: Fri Mar 15, 2019 9:48 am 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 31
Thank you so much, this works perfectly :)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: googlebot


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
A2 Hosting