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.

General Questions /

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

breaking menu title into two line


Reply


8 Posts   1381 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 [url=http://php.net/manual/en/function.str-replace.php]str_replace[/url] 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, 510 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