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

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
minneapolisite
Forum Members
Forum Members
Posts: 24
Joined: Sat Feb 23, 2008 1:15 pm

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

Post 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.
Last edited by minneapolisite on Sun Jul 15, 2012 1:40 pm, edited 1 time in total.
minneapolisite
Forum Members
Forum Members
Posts: 24
Joined: Sat Feb 23, 2008 1:15 pm

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

Post 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}

User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

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

Post 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
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Post Reply

Return to “Layout and Design (CSS & HTML)”