By trevornz on
Hi There
Does any one know how to create a line break in a Drupal title? To force the title over two lines.
I've tried
with no joy. Is it possible?
Hi There
Does any one know how to create a line break in a Drupal title? To force the title over two lines.
I've tried
with no joy. Is it possible?
Comments
me too
I'd also love to know if there is a method for doing this. Many of the articles I publish are multi-part, and it would be great to have a way to break them up.
Very Hackish Suggestion
I’m trying to do the same at the moment. From a semantic point of view, this is problematic IMO because adding line break information to text rendered inside a header tag would mean adding display markup at the wrong place.
Anyway, one of my customers is asking for it, and he probably won’t buy the semantic argument. ;-) So my first and admittedly hacky route would be to add some unobtrusive character (maybe ‘•’ or ‘·’ ) in the title text at the place where the line break is intended and convert this to a
<br/>when the title is rendered. Putting a<br/>in the title text will produce strange results for those using RSS readers, so an inconspicuous, yet easily insertable character would probably be best suited.I’m going to implement this in one of my local modules and report back here, but I guess you shouldn’t expect this to become mainstream, as one shouldn’t insert display markup where it doesn’t belong. Additionally, a forced layout will break when users change display text size.
Cheers,
Mathias
Even more hackerish solution
Hey,
mmaul, that's a lot of work. ;-) You can just go to MS Word's symbol table and "Special Characters" and use those blank em spaces there. The blank spaces is treated differently from the space bar's space and can push your titles to the next line. Hope this helps.
Thanks,
Ken
em space
I tried this. It seemed to work in the preview, but then it turned into a question mark when I saved, and then I got a fatal error in includes/common.inc (Unsupported operand types) and now can't get back to the page to edit out the em space.
So, maybe back to the drawing board with this one...
Thanks anyway!
Nearly there
Ken,
this wouldn’t have worked with this specific client. He couldn’t even find the “|” character, so he wouldn’t have been able to find, insert and remember any special whitecase characters …
Mathias
Eerie … two years later, I
Eerie … two years later, I find my own post after doing a Google search for the same issue. ;-)
(BTW, I *did* manage to convince the client, so I didn’t implement the proposed solution.)
I solved this by adding a
I solved this by adding a subtitle field and some theming in node.tpl.php and page.tpl.php.
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
Use CSS
I used CSS to break up my title over two parts. I used the "width" tag and made it progressively smaller till the title broke over two parts.
I was just about to use this
I was just about to use this approach as well. If you use it, you have to be prepared for lines to break unpredictably, depending on the length of the words in your content. For a small amount of content, I found it most useful to specify breaks manually. I used the approach from this link: http://drupal.org/node/28537
http://drupal.org/node/28537
I used the instructions here: http://drupal.org/node/28537
but added a break also, so my template.php looks like this:
Is not working for me
@keva - This is not working for me. The php doesn't seem to be loaded correctly. When trying to load a node, the page displays some lines of the .php file, visible to the end-user; and further more, e.g. the breaks aren't formatted.
Simple solution
I only wanted to handle line breaks. I make use of the 'pipe' character to delimit a line break:
This title is split|Now on the second line
Copy block.tpl.php from /modules/block to your
/templates folder,
Look for the line where the block title is output:
<?php print $block->subject ?>Change it to
<?php print str_replace('|','<br />',$block->subject) ?>Remember to clear your theme cache so the template file will be recognised!
Brilliant
I love this solution. Many thanks :)
Thank you, this was a great
Thank you, this was a great solution for me. After using a similar thing in a block template (to control the output of the Delta block for page title), I used this code in html.tpl.php to control the output of the html (head) title, so the pipe character didn't show in the browser tab.
This is the solution I used
This is the solution I used as well – it's only now that I see that this opens a can of worms applied to the node title: You need to fix the HTML head, views using titles etc. as well or all your outputs are cluttered with pipe symbols.
Is there a way to invoke this via some kind of hook so it happens before additional processing?
I recall handling this via a special linebreak character once but couldn't reproduce this behaviour on recent installations.
Ok, so regarding the can-of
Ok, so regarding the can-of-worms-aspect of starting to fix up your title output everywhere on the site (RSS feeds, content lists, search results …) I recommend against messing with the title field and considering the following approach:
Whenever the system is using the internal title display – on searches, RSS feeds etc, the version without special characters / linebreaks will be available without additional hotfixing from your side.
The only downside of this approach is, that it takes a bit of fiddling to apply it on an already running site.
I carefully tried this, without success
@appaulmac - Would you have any idea as to why this is not working for me? I specifically find all the files and folders you mentioned, and adjusted the lines and copied the files in to the correct folder of my Bootstrap sub-theme. Even after clearing all caches, the "|" doesn't brake the lines ...
controling line breaks in block title
- controling line breaks in block title -
this replacement : print str_replace('|','
',$block->subject)
works right, and more than this tells how to modify whatever you want, from default template
to specific template,
Thanks very much...
Line Break on Title
To create a line break you need to use the constant PASS_THROUGH
Example
drupal_set_title('text on line 1
text on line 2', PASS_THROUGH);
Reference: https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drup...