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

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: if file exists show it, if not don't show anything
PostPosted: Thu May 23, 2019 3:34 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 54
I'm using this snippet to display file in a div if it exist.

\$1:
 
{if file_exists($entry->fields.Image2)}
 <div class="col-md-6">
<img src="{$entry->file_location}/{$fields.Image2->displayvalue}{$entry->fields.Image2->displayvalue}" class="img-responsive">
</div>
{/if}


if I write it this way the image is not displaying.

if I write it with " !file_exists " the image is showing.

I have also written it like "{if file_exists($entry->fields.Image2)== false}"

but it gives the same result

Some of my posts have an image in this custom field and others don't.
those how don't have it always shows a broken image.

Is there another way to do this kind of operation or am I misunderstanding something?


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: if file exists show it, if not don't show anything
PostPosted: Thu May 23, 2019 4:06 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 54
Ok I figured this Out.

I made it work by doing the following:

\$1:
{capture name="cust_img"}{$entry->fields.Image2->displayvalue}{/capture}
{if empty($smarty.capture.cust_img)}
 
 {else}
 <div class="col-md-6">
 <img src="{$entry->file_location}/{$fields.Image2->displayvalue}{$entry->fields.Image2->displayvalue}" class="img-responsive">
 </div>
{/if}



Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: if file exists show it, if not don't show anything
PostPosted: Fri May 24, 2019 10:54 am 
Offline
Dev Team Member
Dev Team Member

Joined: Mon Nov 28, 2011 9:29 am
Posts: 3124
Location: The Netherlands
Without testing I'd rewrite to:

\$1:
{if !empty($entry->fields.Image2->displayvalue)}
 <div class="col-md-6">
 <img src="{$entry->file_location}/{$fields.Image2->displayvalue}{$entry->fields.Image2->displayvalue}" class="img-responsive">
 </div>
{/if}


Capture is said to be inefficient. The empty statement block is not nice.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


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:  
Hosting Nation - Managed CMSMS Hosting