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

breaking menu title into two line


Go to End


8 Posts   1852 Views

Avatar
Rishi

Community Member, 97 Posts

11 March 2010 at 7:21am

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

Avatar
Juanitou

Community Member, 323 Posts

11 March 2010 at 9:52am

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

Avatar
Rishi

Community Member, 97 Posts

12 March 2010 at 8:21am

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

Avatar
Juanitou

Community Member, 323 Posts

12 March 2010 at 11:06am

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

Avatar
Greg1

Community Member, 28 Posts

12 March 2010 at 1:06pm

Edited: 12/03/2010 1:07pm

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)

Avatar
Rishi

Community Member, 97 Posts

14 March 2010 at 6:20am

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

Avatar
Mo

Community Member, 541 Posts

14 March 2010 at 9:23am

Edited: 14/03/2010 9:24am

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

Avatar
Rishi

Community Member, 97 Posts

14 March 2010 at 8:55pm

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