Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Add a menu item
sottwell
New
Can someone explain clearly how to add a menu item to the main menu? All I want to do is add a link back to the site's home page at the beginning of the menu. Version 2.0.3
Tagged:
3
Comments
In your new theme directory create the directory: Copy this file: to: Edit the copied default.master.php by finding this line (it's line 14 on my file): Immediately below it, insert this line: So that it now looks like this: Edited this last bit to change config.php, not config-defaults.php. my Bad.
Save that file then open: Add this line: If you do all that successfully, Bob's your Uncle, as they say round here
If this method isn't technically the correct way to do things, I stand to be corrected
I did have to put the actual URL to the site's home page in the AddLink third parameter, though, as the '/' value there created a link to mydomain.org/forum/, rather than mydomain.org. Once I get more familiar with how this works, and start getting into the actual code, I'll see if I can determine where it's doing that. At least I would consider that a bug, as '/' should definitely be the web root, not the Vanilla root.
It might have changed since original post was written, I'm using V.209 at present
first...how would i modify this to have the link open in a new window? ( i tried adding on a target="_blank" as a long shot... but no go...)
second, how can i make it so the page that this links to is only accesible if the the user is logged in?
@razlex To make it only accessible to logged in users, use 'Garden.SignIn.Allow' as the permission. AddLink also accepts another argument for attributes on the end ('attribute' => 'value').
Put it all together and get something like this: [incorrect removed, see below]
$this->Menu->AddLink('TEST', T('TEST'), '../en/board.html'), array('target' => '_blank');
and it gives me a syntax error.... any ideas?
i also tried
array('Garden.SignIn.Allow')
one at a time, (and both together) but get syntax errors on both...
in my default.master.php, ive addes the following line:
$this->Menu->AddLink('TEST', T('TEST'), '../en/board.html', array('target' => '_blank'));
so... no more syntax errors.... but when i click the link, it still just replaces the current document instead of loading a new window/tab..... just my luck
just tried again with:
$this->Menu->AddLink('YourLink', T('YourLink'), '../en/board.html', array('Garden.SignIn.Allow'), array('target' => '_blank'));
still just loads in same window.... does that fact that i'm using the embed plugin play into this problem?
PS: You can't just omit arguments like you were trying above, something needs to go in its place every time or it doesn't know what the values mean. The way to skip array('Garden.SignIn.Allow') would be to put just array() in its place.
you're a life saver! now i don't have to get chewed out for not having this site done tomorrow (which i'm not getting paid for...hahaha)
Be interested to see if an id can be assigned to the link. If someone knows the code, let me know, driving me nuts here. Plus, need to add menu item, within a theme. So adding the function within config wont work ... for anyone else. Is there a method within themes this can be done.
There was an error rendering this rich post.
The last argument simply becomes array('target' => '_blank', 'id' => 'GoesHere')
Your theme hooks file can have a Setup method just like a plugin, which can do a "SaveToConfig" to set that variable in your config.
conf/config-defaults had the "$Configuration['Garden']['Menu']['Sort']