Adding Line Breaks in Menu Text [solved]

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
raindogmx

Adding Line Breaks in Menu Text [solved]

Post by raindogmx »

I posted this solution to a very old thread so I'm posting here again.

Someone asked about how to insert line breaks (and other HTML tags) into menu texts. The problem is that when you put a tag into the menu text for example "My menu
item" then the tag will appear literally on the page.

I used this with success in a menu template:

{$node->menutext|replace: '_br_' : '
'}

It means the menu text should have '_br_' where you want the line breaks to appear. That will tell smarty to replace _br_ with an actual line break tag.
Didiero

Re: Adding Line Breaks in Menu Text [solved]

Post by Didiero »

Thank you for this solution. I am a newbie and needed some time to get this to work. The problem were the blanks after the first colon and around the second colon. They produced a Smarty error. This might be obvious for a programmer, but maybe not for a designer. Here is the correct string without the blanks: {$node->menutext|replace:'_br_':'
'}.

In your menu template change every occurrence of {$node->menutext} to {$node->menutext|replace:'_br_':'
'}.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Adding Line Breaks in Menu Text [solved]

Post by Dr.CSS »

May I ask what these are for, won't it put a break after the menu text?...
Didiero

Re: Adding Line Breaks in Menu Text [solved]

Post by Didiero »

It replaces the string "_br_" in the menutext field in the backend with a
-Tag in the frontend. If a longer menutext needs two or more lines in a vertical menu you can tell it where the line breaks should be using this method.
christiaans
Power Poster
Power Poster
Posts: 300
Joined: Tue Mar 04, 2008 10:37 am

Re: Adding Line Breaks in Menu Text [solved]

Post by christiaans »

Didiero wrote: It replaces the string "_br_" in the menutext field in the backend with a
-Tag in the frontend. If a longer menutext needs two or more lines in a vertical menu you can tell it where the line breaks should be using this method.
Could come in handy in some cases I reckon :).
Didiero

Re: Adding Line Breaks in Menu Text [solved]

Post by Didiero »

This trick can also be used in the title as is described here.
Post Reply

Return to “Tips and Tricks”