Styling the Unstylable: node titles and block titles

“So can the world’s most flexible CMS not do that?”, the client asked.
“We just want to have a newline in our block title and italize the first part, in a smaller font.”
Like so:

From the makers of Jaws
False Teeth II

It seemed a reasonable request. But for reasons of consistency and security, Drupal core’s default behaviour is to indiscriminately filter/neutralise all markup in all titles.

"Oh and we may want to embed a link in that title too”, the client added.

“Let us check if there’s a module for that and get back to you”, we said, somewhat worried there might not be one.

Turns out, there is a module for that. It’s clever and small and secure and works a treat (4000+ installs can’t be wrong): HTML Title.

But it doesn’t do blocks.

Plus the author has stated he draws the line at non-semantic HTML elements, i.e. at some of the tags we needed. Which is fair enough. Allowing too many tags may open a can of worms ...

So how to keep this client (and no doubt many others) happy?

You could hack core.   No I didn’t write that.

You could abuse, or shall we say, re-purpose through CSS, one of the tags allowed by HTML Title. In very much the same way as those scaleable font icon libraries like FontAwesome do, you could redefine the <i> tag for instance, to effectively mean a line break. Similar for <mark>, <q> etc.
Not sure how one would or want to do <a>?

Also to a content editor this is not an intuitive approach. And it still wouldn’t helps us with our block titles.

So we went back to the client and said: “There wasn’t a module for it…. but there is now: HTML Title Trash”.

Like its parent, this newborn is totally XSS-safe. To keep the admin title listings on the admin/content and admin/structure/block pages presentable, the module strips out any tags there, while letting those same tags through to do their thing when content is presented to the visitor.

Now you too can satisfy those demanding customers. Without coding or hacking core.

For beginner Drupal developers amongst you, both modules are worth checking out, as they use some well-targeted, less common hooks.


File under: 

Install Apache Solr 5 and Drupal Search API on your laptop in minutes

Read More »

Add new comment