Page 1 of 1

[SOLVED]Alternative content for empty content_image value

Posted: Mon Sep 14, 2009 4:10 pm
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

Re: Alternative content for empty content_image value

Posted: Fri Sep 18, 2009 9:39 pm
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}