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   1773 Views

Avatar
LANKO

Community Member, 3 Posts

6 November 2008 at 6:23am

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

Community Member, 712 Posts

6 November 2008 at 9:31am

Edited: 06/11/2008 9:31am

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

Community Member, 3 Posts

6 November 2008 at 9:31pm

thanks, it helps)