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
[SOLVED]Alternative content for empty content_image value
[SOLVED]Alternative content for empty content_image value
Last edited by Tetsuo on Wed Aug 07, 2013 2:41 pm, edited 1 time in total.
Re: Alternative content for empty content_image value
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:
Should be turned into this:
BTW, {else} isn't closed with {/else}, just with the final {/if}. You could get:
{if}
{elseif}
{else}
{/if}
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}
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}
{if}
{elseif}
{else}
{/if}