• 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  [ 2 posts ] 
Author Message
 Post subject: troubles with {if}]{elseif}{else}
PostPosted: Wed May 22, 2019 3:32 pm 
Offline
Forum Members
Forum Members

Joined: Wed Aug 08, 2018 4:59 pm
Posts: 55
I've been trying to make this if statement work as I want it to:

it is a part of a bigger loop that iterates through a bunch of articles.

If $entry->fields is empty it should get an image from {$entry->file_location}

If $entry->fields is still empty after that the code should look for image in the content.

and if there is no image still showing it should display the <img src="uploads/images/img-01.jpg" class="img-responsive"/>

The problem is when the code looks like it does below the "<img src="uploads/images/img-01.jpg" class="img-responsive"/>"

is the only image being displayed.

but if I use " !empty " for the {if} and {elseif} the "<img src="uploads/images/img-01.jpg" class="img-responsive"/>" in the {else} is never displayed

can someone help me out here?

\$1:
{if empty($entry->fields)}       
<figure>
  {foreach from=$entry->fields item='field'}
        {if $field->type == 'file'}
          {if isset($field->value) && $field->value}
           <img src="{$entry->file_location}/{$field->value}" class="img-responsive"/>
          {/if}
        {/if}
  {/foreach}
</figure>
 
{elseif empty($entry->fields)}
<figure>
  {cgsi_getimages assign='imageinfo' nocontent=1}{$entry->content}{/cgsi_getimages}
       {foreach from=$imageinfo item=image name=pic}
 {if $smarty.foreach.pic.first}<img src="{$image.src}" class="img-responsive"/>{/if}
{/foreach} 
</figure>
{else}
<figure>
<img src="uploads/images/img-01.jpg" class="img-responsive"/> 

</figure>
{/if}
 


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: troubles with {if}]{elseif}{else}
PostPosted: Wed May 22, 2019 4:06 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Feb 25, 2009 4:25 am
Posts: 864
Location: Victoria, BC
$entry->fields is probably never empty, you'll want to verify that first. You'll probably need to test the contents of the specific field, not just that extra fields exist.

In the sample you pasted, the first {if} and the {elseif} are testing the same thing, so the elseif will never be true.

Another thing you may want to look at to simplify your coden a bit is the Smarty |default modifier. You can just call the field and set a default if it's empty.
e.g. {$myimage|default:'path/image.jpg'}

_________________
Not getting the answer you need? CMSMS support options


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  [ 2 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