I am trying to use this module to style each node's title differently, specifically, to display each node's title in a different color.

I have created a list field of colors and had thought to pull it's value into the pattern field via a token. That would would set the color value in an inline css declaration.

It hasn't worked. I'm wondering if there's a less direct way to do it? Perhaps another module? Or a setting? I could probably do it with php, if only I knew enough php to work out the couple of lines it's likely to take.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bforchhammer’s picture

Drupal core does not allow HTML in node titles, so I don't think this is the right module for your use case...

I think the way I would do it is the following:
1) create a field which corresponds to your color
2) modify the node template file, read the field value and assign a node-class respectively.
3) style the title color based on the set node-class.

Instead of modifying the node template file, there may also be a preprocessing function which you can override instead.

mastoll’s picture

You are correct, @bforchhammer.

Fortunately, I am using Display Suites.

I was successful by doing the following:
1) added a field with corresponding color options to the content type (field_color_for_title)
2) added a Display Suites CODE field (Administration » Structure » Display Suite » Fields) in which the code is
[node:title]

Notice the use of the field tokens in the code.
3) hid the node title in DS and moved this DS-code-field to the top of the display.

It may not be so clever to force an inline style. I could have made the color field a class name instead, and then styled the class in my css. But sometimes I find I just have to do it this way. I may get to pay the piper later.

bforchhammer’s picture

Status: Active » Fixed

I think this can be considered fixed :)

rolfmeijer’s picture

Status: Fixed » Active

I would like to reopen this one because I think this module shouldn’t care about saving HTML in the title. According to Handle text in a secure fashion modules should not sanitize data when saving it to the database. It should be sanitized when displayed. Over at Automatic Node Titles the same discussion has taken place, see #878570: Do not sanitize title in function _auto_nodetitle_patternprocessor.

According to this, the line:
$output = preg_replace('/[\t\n\r\0\x0B]/', '', strip_tags($output));
could be dropped.

The consequence of dropping this particular line is that it is possible to use the HTML Title module to control the display of (certain) HTML-tags.

This issue might be related with the solution proposed in #2120055: Trim auto-generated labels.

rolfmeijer’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
1.18 KB

Added a patch.

rolfmeijer’s picture

As it might be related to #2120055: Trim auto-generated labels, it may be wise to “formalize” this relation.

rolfmeijer’s picture

bforchhammer’s picture

I don't think we should simply delete the line due to the fact that it has been part of the module for a long time and some sites might rely on it, e.g. if the use custom PHP code and don't clean up the label on their own.

However, we could definitely add a configuration option which allows to disable sanitation of labels... That option should probably include trimming as well (as described in the related issue).

bforchhammer’s picture

Status: Needs review » Needs work
rolfmeijer’s picture

Ah yes, I hadn’t thought about backwards compatibility. You’re right, although it makes it quit a bit more complicated. I don’t have a patch for that at hand, but I see what I can do.

kukle’s picture

Deleting the line $output = preg_replace('/[\t\n\r\0\x0B]/', '', strip_tags($output)); works for me. But I want a href to a file on a network drive. The html is in the title, but is readable as plain text, not as a link.

kukle’s picture

I want to have a working link with some kind of url like this one: <a href='file:///Q:\INFO\Inside\inside_55.pdf'>test</a>

BWPanda’s picture

Category: Support request » Feature request
Status: Needs work » Needs review
FileSize
1.58 KB

Here's a patch that adds an option to strip HTML tags and only strips if the option is enabled.

yogeshmpawar’s picture

Status: Needs review » Reviewed & tested by the community

it adds the option to strip HTML tags. patch is good to go.

purushotam.rai’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

  • purushotam.rai committed 514f4ea on 7.x-1.x authored by BWPanda
    Issue #2204195 by rolfmeijer, BWPanda, purushotam.rai, Yogesh Pawar: Is...
purushotam.rai’s picture

purushotam.rai’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.