How to check if a page has a thumbnail or image?

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
silentcreek
New Member
New Member
Posts: 3
Joined: Fri Apr 13, 2012 8:16 am

How to check if a page has a thumbnail or image?

Post by silentcreek »

Hey everyone,

I'm new to CMSms. However, I'm very pleased with it and managed to convert my template to CMSms very easily (I do know XHTML/CSS/PHP). I guess the most difficult thing so far has been to sign up for this forum (seriously, who came up with that Monty Python question ??? ).

Anyway, what I haven't got working so far is this:
I want to use the {page_image thumbnail=true} template tag to display an image, if the page has one set. But how can I check if the page has a thumbnail assigned within my template? I tried $node->thumbnail but it didn't return anything (I read it may work only in the menu manager).

So, I'm trying to do sth. like this:

Code: Select all

{if !empty($whatever_the_name_of_the_page_thumbnail_variable_is)}
<img src="uploads/images/Hintergruende_und_Logos/{page_image thumbnail=true}">
{/if}
Anyone knows which variable I have to call to check whether there is a thumbnail set for the page?

Thanks a lot,

Timo
mcDavid
Power Poster
Power Poster
Posts: 377
Joined: Tue Mar 31, 2009 8:45 pm

Re: How to check if a page has a thumbnail or image?

Post by mcDavid »

try this:

Code: Select all

<pre>{$node|print_r}</pre>
to see all the page variables
silentcreek
New Member
New Member
Posts: 3
Joined: Fri Apr 13, 2012 8:16 am

Re: How to check if a page has a thumbnail or image?

Post by silentcreek »

Thanks mcDavid,

I tried what you suggested and found out that 1) there is a variable $node->thumbnail but only after the menu manager has been called withing the template. If you try to call the variable before. It won't work at all. 2) Even if you call it after calling the menu manager from within your template, it will only give you the result of the last item that the menu manager processed which often will not be your current page. So, that's pretty useless.

For now, I built myself a workaround by making a small template in the menu manager with this code:

Code: Select all

{foreach from=$nodelist item=node}
{if $node->current==true && !empty($node->thumbnail)}
<img src="uploads/images/{page_image thumbnail=true}" class="pagethumbnail">
{/if}
{/foreach}
This works. But of course it would be nicer if there is a way to check whether there is a thumbnail for the page in the template code.

Cheers,

Timo
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: How to check if a page has a thumbnail or image?

Post by Dr.CSS »

I use this in the menu calls where the normal menu text call is...

{if !empty($node->image)}<img src="{$node->image}" alt="{$node->menutext}" />{else}<span class='{$node->alias}'>{$node->menutext}</span>{/if}

This is used to replace menu text with an image is an image has been chosen in page Options tab, may need to change it for thumbnail...

Used here...

http://dequenesh.org/

And here...

http://dezertdesign.com/pill-dock.html
silentcreek
New Member
New Member
Posts: 3
Joined: Fri Apr 13, 2012 8:16 am

Re: How to check if a page has a thumbnail or image?

Post by silentcreek »

Thanks Dr.CSS.

But if I understand your reply correctly, you use this code in your menu manager template and not directly in your theme, right? My workaround works similar but I was asking for a way to call the thumbnail variable without having to use the menu manager. In my opinion that is far more logical than doing that in the menu manager considering that the thumnail I like to display has nothing to do with any menu.

Cheers,

Timo
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: How to check if a page has a thumbnail or image?

Post by Dr.CSS »

The $node-> call is only used in menu manager...
For now, I built myself a workaround by making a small template in the menu manager with this code:
This is why I posted menu code...
uniqu3

Re: How to check if a page has a thumbnail or image?

Post by uniqu3 »

Code: Select all

{page_image thumbnail='1' assign='my_thumb'}
    {if !empty($my_thumb)}<img src='uploads/images/{$my_thumb}' />{/if}
Post Reply

Return to “CMSMS Core”