Menu with individual images

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
User avatar
thomahawk
Power Poster
Power Poster
Posts: 293
Joined: Fri Jul 25, 2008 10:13 am
Location: Zug, Switzerland

Menu with individual images

Post by thomahawk »

Hello all

Is there a way to set individual images to each page and display it in the menu list?

Thom
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Menu with individual images

Post by Dr.CSS »

I set the page image in site admin > general settings to a folder in uploads/images that holds my menu images then when making pages that need them I go to options > image and select the image for that page, in the menu I add...

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

This way if it doesn't have an image it shows the menu text...

[NOT TESTED IN 2.0]
User avatar
thomahawk
Power Poster
Power Poster
Posts: 293
Joined: Fri Jul 25, 2008 10:13 am
Location: Zug, Switzerland

Re: Menu with individual images

Post by thomahawk »

Hi Dr. CSS
Thanks for that input. I will try this and as I already set page images for on top of the page, I only need to put in the menu code. Great!
User avatar
thomahawk
Power Poster
Power Poster
Posts: 293
Joined: Fri Jul 25, 2008 10:13 am
Location: Zug, Switzerland

Re: Menu with individual images

Post by thomahawk »

actually my image is a content_image, but this does not work

{if !empty($node->content_image)}<img src="{$node->content_image}" />{else}{/if}

Not possible?
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Menu with individual images

Post by Dr.CSS »

Because that isn't available for the menu manager, to access images in the menu manager you need to use what I showed...
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Menu with individual images

Post by velden »

It is possible but less efficient than $node->image.

For CMSMS 2.0 check help of the (by default) available page_attribute tag.

For CMSMS 1.x:

Module CGSimpleSmarty provides a method:
get_page_content($alias[,$block][,$assign])

Returns the text of a specific content block of another page.

Arguments:

$alias - The page alias to extract content from.
[$block] - (optional) The name of the content block in the specified page. If this variable is not specified the value of the default content block (content_en) is assumed.
[$assign] - (optional) The name of a variable to assign the results to.


Example:

The 'second' block of the 'about' page is {cgsimple::get_page_content('about','second','foo')}{eval var=$foo}
so something like:

Code: Select all

...
{cgsimple::get_page_content($node->alias,'my_image_blockname','tmpImg')}
{if !empty($tmpImg)}  
   ...do useful things here...
{/if}
...
Much less efficient because it has to create a Content Object for every
single page in the menu to get the image information if any.

Didn't test code above btw. Might need to check for specific content types before calling method (Separator, Section Header etc don't have custom content blocks)
User avatar
thomahawk
Power Poster
Power Poster
Posts: 293
Joined: Fri Jul 25, 2008 10:13 am
Location: Zug, Switzerland

Re: Menu with individual images

Post by thomahawk »

Thanks you. In that case I try to switch the main image of each page over to use the option - image and use the same for the menu image. I will post here if it worked.

Thanks again
Thom
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Menu with individual images

Post by velden »

Note that you can move that field to the main tab of the edit content page.

Global Settings -> Content Editing Settings -> 'Basic Properties' (multi select box).
User avatar
thomahawk
Power Poster
Power Poster
Posts: 293
Joined: Fri Jul 25, 2008 10:13 am
Location: Zug, Switzerland

Re: Menu with individual images

Post by thomahawk »

Thanks for the suggestion.

Unfortunately it does not work.

I have set the image folder in "Administration > Global Setting" and changed the template to include {$node->image} instead of content_image, so the code is:

<div class="produkte-topbild" style="background-image:url({$node->image})">

I also changed the code for the menu to include {$node->image}.

It works as far as on editing the page, my list of images appears for the "image" tag and I selected the image for that page. But in the end, the image does not show on the page or with the menu. Checking the page sourcecode the result is:

<div class="produkte-topbild" style="background-image:url()">

So, no url is included, it is empty.
What did I do wrong?
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Menu with individual images

Post by Dr.CSS »

The other post sounded like the image was going to be used in the menu now it sounds like it is going to be in the template as background image, $node->image only works in the menu manager the other image call, content_image is available for things like background...
User avatar
thomahawk
Power Poster
Power Poster
Posts: 293
Joined: Fri Jul 25, 2008 10:13 am
Location: Zug, Switzerland

Re: Menu with individual images

Post by thomahawk »

Hi Dr. CSS. Thanks for your post. Yes I supposed there may be yet again a limitation for that tag (how many times those tag limitations destroyed my plans – I quit counting). In fact I need the same {$node->image} once in template, once in menu and I tried both, its not working either way.

Thom
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Menu with individual images

Post by velden »

What version of CMSMS are we talking about?
Yes I supposed there may be yet again a limitation for that tag (how many times those tag limitations destroyed my plans – I quit counting)
The only limitation is your own imagination ;-)

$node->image in Menu Manager
{page_image} tag in page template
Help for the page_image tag
What does this do?

This tag can be used to return the value of the image or thumbnail fields of a certain page.
How do I use it?

Insert the tag into the template like: {page_image}.
What parameters does it take?

thumbnail - Optionally display the value of the thumbnail property instead of the image property.
(optional) assign (string) - Assign the results to a smarty variable with that name.
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: Menu with individual images

Post by Jeff »

In the old MenuManager there was a parameter on whether or not to load all the page attributes into the $node object. Read the help, that might be the issue.

I don't know if this is still the case in 2.x with Navigator..
User avatar
thomahawk
Power Poster
Power Poster
Posts: 293
Joined: Fri Jul 25, 2008 10:13 am
Location: Zug, Switzerland

Re: Menu with individual images

Post by thomahawk »

General info: I am using CMSMS 1.12

Thanks Jeff. In fact it is the opposite. the menu option you mean is loadprops but it is on by default and does only prevent things like $node->image to be loaded if it is specifically set to loadprops="0"

This is not the case in my menu setting.

My images are showing fine on the pages using this in the template
style="background-image:url(uploads/produkte-titelbilder/{page_image})"

but within the menu they do not show up. This is my menu manager code
{if !empty($node->image)}{else}<img src="{$node->image}" />{/if}
<a class="produkt" href="{$node->url}">{$node->menutext}</a>

The resulting html code does only include the page link, no image tag. So it seems as the menu manager sees node->image as empty.
User avatar
thomahawk
Power Poster
Power Poster
Posts: 293
Joined: Fri Jul 25, 2008 10:13 am
Location: Zug, Switzerland

Re: Menu with individual images

Post by thomahawk »

Unless I don't understand it right?

With {page_image} on a template, I get a field on the page editor to set an image from the folder (as set in admin–global settings).

This is the same image that the menu manager displays by using ($node->image), right?


By the way: I checked variables using {get_template_vars} I don't see any "image" variable on the page. Nevertheless the image shows up fine on that page.
Locked

Return to “The Lounge”