Jump to:

23023 Posts in 11882 Topics by 2830 members

General Questions

SilverStripe Forums » General Questions » breaking menu title into two line

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

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

Page: 1
Go to End
Author Topic: 1277 Views
  • Rishi
    Avatar
    Community Member
    97 Posts

    breaking menu title into two line Link to this post

    hello
    i have menu title which are too long and i need to break them,
    please help me in breaking them,as i am new in silverstripe any code will be a great help
    my menu links are like this

    -university list
    -projects list
    -student
    i would liek to dispaly them as
    -University
    list
    -Projects
    list
    Student

    thank you in advance

  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: breaking menu title into two line Link to this post

    Hi!

    Insert a <br /> tag where needed in your Menu Title field and serve it in your templates with $MenuTitle.RAW (more info: http://doc.silverstripe.org/doku.php?id=text).

    Hope it helps,
    Juan

  • Rishi
    Avatar
    Community Member
    97 Posts

    Re: breaking menu title into two line Link to this post

    thank you Juanitou for the link that has solved my many problem but not the one with menu
    from one of the forum i got this code but dont no how to proceed with it

    public function getMenuTitleWithNewlines() {
    return $this->addNewlines($this->obj('MenuTitle')->XML());
    }

    function addNewlines($title) {
    return /* $title with &amp; replaced by <br> */;
    }

    }

    Then in your template, use $MenuTitleWithNewlines instead of $MenuTitle.

    now i dont no how to insert a <br> in menutitle

  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: breaking menu title into two line Link to this post

    Hi!

    I don’t understand well where did you find this unfinished code. In order to replace &amp; with <br /> you could use a str_replace for the return value of addNewlines().

    Hope it helps,
    Juan

  • Greg1
    Avatar
    Community Member
    28 Posts

    Re: breaking menu title into two line Link to this post

    I'd suggest that you control this with CSS as the problem sits at the presentation layer and just set a maximum width of the element (or padding/margin if appropriate)

  • Rishi
    Avatar
    Community Member
    97 Posts

    Re: breaking menu title into two line Link to this post

    i tried breaking that way but then it is breaking those menu title also which i dont want

  • Mo
    Avatar
    Community Member
    485 Posts

    Re: breaking menu title into two line Link to this post

    Hi Rishi,

    If you added a checkbox to your page class, something like 'BreakMenuSpaces', you could then use this code in your page controller, to check if someone had ticked the option to break menu spaces:

    public function getMenuTitleWithNewlines() {
    if($this->BreakMenuSpaces)
    return str_replace(' ','<br/>',$this->MenuTitle());
    else
    return $this->MenuTitle();
    }

    You would then access that in your template via: $MenuTitleWithNewlines

    Hopefully that will work, though I haven't tested it.

    Cheers,

    Mo

  • Rishi
    Avatar
    Community Member
    97 Posts

    Re: breaking menu title into two line Link to this post

    thank you Mo
    if i can make this works then it will be the best solution i will try it and let you know thanks once again

    1277 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.