Page 1 of 1
How to check if a page has a thumbnail or image?
Posted: Fri Apr 13, 2012 9:17 am
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
Re: How to check if a page has a thumbnail or image?
Posted: Fri Apr 13, 2012 9:49 am
by mcDavid
try this:
to see all the page variables
Re: How to check if a page has a thumbnail or image?
Posted: Fri Apr 13, 2012 1:54 pm
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
Re: How to check if a page has a thumbnail or image?
Posted: Fri Apr 13, 2012 7:03 pm
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
Re: How to check if a page has a thumbnail or image?
Posted: Mon Apr 16, 2012 2:33 pm
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
Re: How to check if a page has a thumbnail or image?
Posted: Tue Apr 17, 2012 5:37 pm
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...
Re: How to check if a page has a thumbnail or image?
Posted: Tue Apr 17, 2012 6:01 pm
by uniqu3
Code: Select all
{page_image thumbnail='1' assign='my_thumb'}
{if !empty($my_thumb)}<img src='uploads/images/{$my_thumb}' />{/if}