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.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

newbies help with adding images to main menu


Reply

3 Posts   1728 Views

Avatar
LANKO

6 November 2008 at 6:23am Community Member, 3 Posts

I want to use images instead of text in main menu.

I add:

class Page extends SiteTree
{
   static $db = array(
   );
   static $has_one = array(
      'MenuImg' => 'Image'
   );
...

and

function getCMSFields()
   {
      $fields = parent::getCMSFields();
      $fields->addFieldToTab("Root.Content.Images", new ImageField('MenuImg','Menu image'));

...

than attach my image for menu.

but i can't get how to use it in my template.

i use <% control Menu(1) %> to get info about menu ($Title, $Content) but there is no $MenuImg there.

how i can use $MenuImg in my templates?

Avatar
Hamish

6 November 2008 at 9:31am (Last edited: 6 November 2008 9:31am), Community Member, 712 Posts

So you've put $MenuImg in your template? It should work eg:

<% control Menu(1) %>
<% if MenuImg %>
$MenuImg
<% else %>
<!-- debug: menu image missing for page $Title -->
$Title
<% end_if %>
<% end_control %>

Avatar
LANKO

6 November 2008 at 9:31pm Community Member, 3 Posts

thanks, it helps)