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
Thank you! Exactly what I needed. I had it up to the part of what to put in the default.master.php; I had a funny feeling that just putting in the HTM for a link wouldn't be the Vanilla way!
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.
I think there is an error in there (but it's minor) it did not work for me until I put default.master.php in
themes/yournewtheme/views/default.master.php
and I used "../news" as the third parameter i.e. a relative URL to my WordPress installation. It might have changed since original post was written, I'm using V.209 at present
@DavyB You are correct; I've edited @Caramboo's comment to fix this (hoping he doesn't mind).
@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]
so i tried this: $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...
man.... i dunno what i'm doing wrong.. haha... 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 ;)
i tried with and without it thinking it might be messing with something.... same result... =/ 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?
The fifth argument is applied to the < li >, it's the sixth that gets put on the anchor tag.
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.
Thank you SO much!! 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)
one more question... this may be a long shot... but is there any way so that the pages i have opening in the new window are private? meaning, if you're logged into the forms, they open... but if you just go directly to the url, it'll say accessed denied, or redirect you to the form login or something along those lines?
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.
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):
if ($this->Menu) {Immediately below it, insert this line:$this->Menu->AddLink('Home', T('Home'), '/');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
- Spam
- Abuse
- Troll
4 • Off Topic Insightful Awesome LOL •- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
- Spam
- Abuse
- Troll
1 • Off Topic Insightful Awesome LOL •- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Developer at Vanilla Forums, Inc. [GitHub, Twitter]
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •It might have changed since original post was written, I'm using V.209 at present
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •@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]
Developer at Vanilla Forums, Inc. [GitHub, Twitter]
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •$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...
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Developer at Vanilla Forums, Inc. [GitHub, Twitter]
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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 ;)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Developer at Vanilla Forums, Inc. [GitHub, Twitter]
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
Developer at Vanilla Forums, Inc. [GitHub, Twitter]
- Spam
- Abuse
- Troll
2 • Off Topic Insightful Awesome LOL •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)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
422 Real Estate Australia , now open Check it out
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •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.
Developer at Vanilla Forums, Inc. [GitHub, Twitter]
- Spam
- Abuse
- Troll
1 • Off Topic Insightful 1Awesome LOL •conf/config-defaults had the "$Configuration['Garden']['Menu']['Sort']
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •Never edit config-defaults.php. Add the entry to config.php.
Developer at Vanilla Forums, Inc. [GitHub, Twitter]
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Awesome LOL •