Page 1 of 1

[SOLVED] Display content img if exists, else display default

Posted: Fri Jul 13, 2012 9:12 pm
by minneapolisite
In my template, I want to display the Content Image if one is specified. If none is specified, I want to display a default image.

I'm inputting the content image here:
Image

This is my code (rough draft). The RED section is the line that I'm stuck on!

Code: Select all

[color=#FF0000]{if content image exists}[/color]
<img src="/uploads/images/{$content_obj->GetPropertyValue('image')}" alt="" width="261">
{else}
<img src="/uploads/images/i-side.jpg" alt="" width="261" height="175">
{/if}
I tried following these instructions, but they are from 2009 and do not work.

Re: Display content img if it exists, else display default i

Posted: Sun Jul 15, 2012 1:39 pm
by minneapolisite
Solution:

Code: Select all


{assign var=page_illustration value=$content_obj->GetPropertyValue('image')}
{if $page_illustration == '-1'}
<img src="/uploads/images/default.jpg" alt="" />
{else}
<img src="/uploads/images/{$content_obj->GetPropertyValue('image')}" alt="" />
{/if}


Re: [SOLVED] Display content img if exists, else display def

Posted: Sun Jul 15, 2012 2:28 pm
by Rolf
Should also work:

Code: Select all

{page_image assign=foo}
{if $foo}
     <img src="uploads/images/page_images/{$foo}" alt="blah" />
{else}
     <img src="uploads/images/page-images/default.jpg" alt="blah" />
{/if}
Or something like:

Code: Select all

<img src="uploads/images/page_images/{$page_image|default:'default.jpg'}" alt="blah" />
Haven't test this though...

grt. Rolf