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.

Archive /

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

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

newbies help with adding images to main menu


Go to End


3 Posts   2227 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)