Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » newbies help with adding images to main menu

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

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

Page: 1
Go to End
Author Topic: 1705 Views
  • LANKO
    Avatar
    Community Member
    3 Posts

    newbies help with adding images to main menu Link to this post

    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?

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: newbies help with adding images to main menu Link to this post

    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 %>

  • LANKO
    Avatar
    Community Member
    3 Posts

    Re: newbies help with adding images to main menu Link to this post

    thanks, it helps)

    1705 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.