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

sottwellsottwell New
edited August 2010 in Vanilla 2.0 - 2.8
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:
«1

Comments

  • edited November 2010
    Create a custom theme rather than edit the default by reading the contents of:
    themes/default/README.txt
    Make sure you switch to the new cloned theme.

    In your new theme directory create the directory:
    themes/yournewtheme/views
    Copy this file:
    applications/dashboard/views/default.master.php
    to:
    themes/yournewtheme/views/default.master.php
    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:

    if ($this->Menu) {
    $this->Menu->AddLink('Home', T('Home'), '/');
    $this->Menu->AddLink('Dashboard', T('Dashboard'), '/dashboard/settings', array('Garden.Settings.Manage'));
    Edited this last bit to change config.php, not config-defaults.php. my Bad.
    Save that file then open:

    conf/config.php
    Add this line:

    $Configuration['Garden']['Menu']['Sort'] = array('Home', 'Dashboard', 'Discussions', 'Questions', 'Activity', 'Conversations', 'User');
    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








  • no, no that's correct, and a nice guide btw ;)
  • sottwellsottwell New
    edited August 2010
    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.
  • @Tim more spam
  • @zodiacdm Got it.
  • Thanks. These bots are rediculous :P
  • edited October 2010
    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
  • I've been working on implementing this into my site... i have 2 questions however....

    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?
  • LincLinc Admin
    edited November 2010
    @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]
  • edited November 2010
    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...
  • My suggestion was missing a parenthesis on the end. Fixed.
  • 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 ;)
  • You're not copying what I typed. You skipped an argument: array('Garden.SignIn.Allow').
  • 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?
  • LincLinc Admin
    edited December 2011
    Crap. This is it:
    $this->Menu->AddLink('YourLink', T('YourLink'), '/path/to/page', array('Garden.SignIn.Allow'), array(), array('target' => '_blank'));
    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.

    There was an error rendering this rich post.

  • LincLinc Admin
    edited December 2011

    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']

Sign In or Register to comment.