Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Creating an Image (rather than Text)-based menu


Go to End


5 Posts   1275 Views

Avatar
Jen

Community Member, 5 Posts

27 June 2012 at 4:47pm

Hi. I am very new to SS, and haven't been programming for well over a decade so I am not quite up to speed with all of the code and syntax in SS. I am trying to create a menu for the home page of my site which uses images as the links instead of text. You can see the page at: http://www.mummydoit.org

The images are meant to be positioned in the white blocks and look like polaroids.

The code I am using is:
<ul class="polaroid">
<% control Menu(1) %>
<li>
<a href="$Link" class="pic-{$POS}">$LinkPic</a>
</li>
<% end_control %>
</ul>

LinkPic is an image field on all top level pages in the site and I have made sure that an image is uploaded for each page. The code is working, but only for the last item in the menu. Can anyone tell me why and how to fix it?

Eventually, I would like for the Home page to not show up on this menu, but I haven't tackled that problem yet. I am assuming it will be some sort of if statement, but if you have any ideas about that as well, I would be grateful.

Thanks.

Avatar
Willr

Forum Moderator, 5523 Posts

27 June 2012 at 6:17pm

If you want to hide a page, untick the 'Show in Menus' checkbox in the CMS (http://2.4.userhelp.silverstripe.org/for-website-content-editors/managing-your-site/). With the missing images it looks like LinkPic isn't set at all, Make sure you can see the image thumbnail in the CMS.

Avatar
Jen

Community Member, 5 Posts

27 June 2012 at 6:54pm

Thanks for the reply. The images are definitely loaded and thumbnails visible.

I actually don't want to hide Home in all menus, just that menu on the home page, so I don't think the checkbox option will do what I need.

Avatar
Willr

Forum Moderator, 5523 Posts

27 June 2012 at 7:44pm

Then take a read of the first couple tutorials and introduce yourself to the page types and templates (http://doc.silverstripe.org/framework/en/2.4/reference/built-in-page-controls). You could do something like <% if URLSegment = home %><% else %> your menu code<% end_if %>. Next thing to check - what is $LinkPic? If you try $LinkPic.ID you should see a series of numbers for each image. If you only see 0's then the images aren't attached.

Avatar
Jen

Community Member, 5 Posts

27 June 2012 at 10:08pm

Ok...feeling very sheepish and deserve an absolute slap upside the head. I was on such a roll adding pics to each page that I forgot to publish them as I went. Doh!

Thanks for the code reference. I will give that a go and see what I can do. Thank you for all the help.