Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML\rich text in Drupal's node title?

Tags:

I need the node titles to be able to display some text formatting.

As far as I understand, Drupal's title field is just plain text, it doesn't allow HTML or any other input format. Is that true? Is there a way to override this, or another solution?

I am working with Drupal 6.

like image 329
daphshez Avatar asked Oct 08 '09 06:10

daphshez


1 Answers

You can pretty easily do this in your theme, there are different ways to do with. The simplest would probably to do it in your template.php

/* this function generates the variables that are available in your node.tpl,
 * you should already have this in your template.php, but if not create it
 */
function mytheme_preprocess_node(&$vars) {
    // It's important to run some kind of filter on the title so users can't
    // use fx script tags to inject js or do nasty things.
    $vars['title'] = filter_xss($vars['node']->title);
}

What happens in the function is that it overwrites the default value for $title in the node.tpl which holds the variable used for the title. It is usually placed within a h1 or h2 tag, so you should be aware of that. The filter_xss is used to only allow basic html tags, so protect the site, you can look at that function here. That are some other filter functions, like check_markup, and filter_xss_admin, but you can give a second param for filter_xss which is an array of allowed tags, so should the default not be good enough, you can just change it to fit your needs.

like image 67
googletorp Avatar answered Oct 12 '22 09:10

googletorp