[SOLVED]Alternative content for empty content_image value

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
Tetsuo
Forum Members
Forum Members
Posts: 58
Joined: Wed Aug 19, 2009 12:00 pm

[SOLVED]Alternative content for empty content_image value

Post by Tetsuo »

Hi

I'm having problems with my syntax working how I want.

I have a content_image block in my CMS that is used for an option image to be placed on pages. When the image is not selected within the CMS from the content_image drop-down menu (ie. it is set to "---none---") I don't want the image, or accompanying HTML, to be displayed at all.

I have written a condition that seems to do this, but when I save and submit a page that has no image set, the loop still executes and I am left with an image that has a src of ="-1"

Can anyone spot what I am doing wrong with my code below?

{content_image block='Caption Image' dir='images' urlonly='true' assign='caption_var'}
{if !empty($caption_var)}


{content block='Caption Text' wysiwyg="false" oneline="true"}

{else}

{/else}
{/if}

You can see it in action on this page
Last edited by Tetsuo on Wed Aug 07, 2013 2:41 pm, edited 1 time in total.
Mantlet
Forum Members
Forum Members
Posts: 114
Joined: Fri Apr 28, 2006 9:42 am

Re: Alternative content for empty content_image value

Post by Mantlet »

I think it isn't working, because the assign property isn't supported, at least not according to the content_image help file. You can also leave the !empty out, you just want the code to show if it is there. And {else} doesn't have to be there if you don't output an alternative code.
So this:

Code: Select all

{content_image block='Caption Image' dir='images' urlonly='true' assign='caption_var'}
{if !empty($caption_var)}
   <div class="caption">
      <img src="{$caption_var}" title="" alt="" />
      <cite>{content block='Caption Text' wysiwyg="false" oneline="true"}</cite>
   </div>
   {else}
      <div></div>
   {/else}
{/if}
Should be turned into this:

Code: Select all

{capture assign='caption_var'}{content_image block='Caption Image' dir='images' urlonly='true'}{/capture}
{if ($caption_var)}
   <div class="caption">
      <img src="{$caption_var}" title="" alt="" />
      <cite>{content block='Caption Text' wysiwyg="false" oneline="true"}</cite>
   </div>
{/if}
BTW, {else} isn't closed with {/else}, just with the final {/if}. You could get:

{if}
{elseif}
{else}
{/if}
Post Reply

Return to “CMSMS Core”