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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Possible to override LeftAndMain::MainMenu()?


Go to End


4 Posts   1116 Views

Avatar
Phill

Community Member, 81 Posts

21 October 2014 at 9:26pm

Hi

I've been trying to override LeftAndMain::MainMenu() with a custom function, is this possible?

So far I've tried creating an extension registered in the yml and creating a custom class that extends LeftAndMain using Object::useCustomClass in the config to point LeftandMain to my new class but neither of these seem to work.

Any ideas on how I could do this?

Thanks

Avatar
kinglozzer

Community Member, 187 Posts

22 October 2014 at 4:48am

Hi Phill,

What are you trying to achieve? There are ways of adding links etc to the menu if that’s what you need.

If you do need something entirely custom, you could override the template framework/admin/templates/Includes/LeftAndMain_Menu.ss and use, for example, <% loop CustomMainMenu %>.

You could then add an extension to LeftAndMain with a CustomMainMenu function and it should pick it up.

Hope this helps,
Loz

Avatar
Dave L

Community Member, 60 Posts

22 October 2014 at 2:43pm

Edited: 22/10/2014 2:43pm

While we're on the topic - I can override LeftAndMain_Menu.ss by putting it in mysite\templates\Includes\LeftAndMain_Menu.ss, but I cannot override it by putting it in mymodule\templates\Includes\LeftAndMain_Menu.ss. Is there something that restricts CMS template overrides in a module?

Avatar
Phill

Community Member, 81 Posts

22 October 2014 at 9:55pm

Thanks kinglozzer that works id overlooked just renaming the function.

@Dave L I believe this is a known issue, you may be able to override it by prefixing your module with zzz_
https://groups.google.com/forum/#!topic/silverstripe-dev/JJd-ryW7erY