[SOLVED] How to use page images (as defined on Page:Options)

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
minneapolisite
Forum Members
Forum Members
Posts: 24
Joined: Sat Feb 23, 2008 1:15 pm

[SOLVED] How to use page images (as defined on Page:Options)

Post by minneapolisite »

I want to make these images:

Image

Show up in the templates:

Image

I know this should be simple, but I can't figure out how to do it. :(
Last edited by minneapolisite on Tue Mar 01, 2011 4:07 pm, edited 3 times in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: How to use page images (as defined on Page: Options tab)

Post by Dr.CSS »

minneapolisite
Forum Members
Forum Members
Posts: 24
Joined: Sat Feb 23, 2008 1:15 pm

Re: How to use page images (as defined on Page: Options tab)

Post by minneapolisite »

Yes, {$content_obj->GetPropertyValue('image')} was exactly what I needed! One follow-up question: how would I wrap an "if" statement around it so the code only shows up if there is an image defined?

{if _____________}
<img src="/uploads/images/{$content_obj->GetPropertyValue('image')}" alt="" />
{/if}
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: How to use page images (as defined on Page: Options tab)

Post by Dr.CSS »

{capture assign="junk"}<img src="/uploads/images/{$content_obj->GetPropertyValue('image')}" alt="" />{/capture} {if !empty($junk)}
{$junk}
{/if}

You capture it and assign a var to it, {$junk}, then if it is not empty, if !empty, show it, {$junk}...
minneapolisite
Forum Members
Forum Members
Posts: 24
Joined: Sat Feb 23, 2008 1:15 pm

Re: How to use page images (as defined on Page: Options tab)

Post by minneapolisite »

Success! You are a peach! :)
minneapolisite
Forum Members
Forum Members
Posts: 24
Joined: Sat Feb 23, 2008 1:15 pm

Re: How to use page images (as defined on Page:Options)

Post by minneapolisite »

Follow-up question:

I currently am using this code:

Code: Select all

{capture assign="page_illustration"}
<img src="/uploads/images/{$content_obj->GetPropertyValue('image')}" alt="" class="illustration" />
{/capture} 
{if !empty($page_illustration)}
{$page_illustration}
{/if}
But when there is not an assigned image, it's outputting this:

Code: Select all

<img src="/uploads/images/-1" alt="" class="illustration" />
How can I make it output NOTHING?
uniqu3

Re: How to use page images (as defined on Page:Options)

Post by uniqu3 »

As it looks like there is a value of -1 if no image selected you could try:

Code: Select all

{capture assign="page_illustration"}
<img src="/uploads/images/{$content_obj->GetPropertyValue('image')}" alt="" class="illustration" />
{/capture} 
{if $page_illustration == '-1'}
{else}
{$page_illustration}
{/if}
But there is for sure more elegant way.
minneapolisite
Forum Members
Forum Members
Posts: 24
Joined: Sat Feb 23, 2008 1:15 pm

Re: How to use page images (as defined on Page:Options)

Post by minneapolisite »

Hm, that suggestion didn't work. ???
uniqu3

Re: How to use page images (as defined on Page:Options)

Post by uniqu3 »

Try this, i tried it on 1.9.3 version and works as expected.

Code: Select all

{assign var=page_illustration value=$content_obj->GetPropertyValue('image')}
{if $page_illustration == '-1'}            
{else}
<img src="{root_url}/uploads/images/{$content_obj->GetPropertyValue('image')}" alt="" class="illustration" />
{/if}
minneapolisite
Forum Members
Forum Members
Posts: 24
Joined: Sat Feb 23, 2008 1:15 pm

Re: How to use page images (as defined on Page:Options)

Post by minneapolisite »

uniqu3, you are my hero! That works great. :) Thank you!
User avatar
pixelita
Power Poster
Power Poster
Posts: 388
Joined: Sun Sep 16, 2007 3:07 am

Re: [SOLVED] How to use page images (as defined on Page:Opti

Post by pixelita »

Uniqu3 is my hero too! That code worked on a client site that I am working on where I want them to be able to associate an image with a page that they create.

And I was Googline for "page_image" because I had been trying to use the {page_image} tag without success.

Am I misunderstanding the purpose of {page_image} perhaps?
Submit your site to the We Love CMSMS showcase
Post Reply

Return to “CMSMS Core”