Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#13 | disable_stripping_tags-2204195-13.patch | 1.58 KB | BWPanda |
Comments
Comment #1
bforchhammer CreditAttribution: bforchhammer commentedDrupal 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.
Comment #2
mastoll CreditAttribution: mastoll commentedYou 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.
Comment #3
bforchhammer CreditAttribution: bforchhammer commentedI think this can be considered fixed :)
Comment #4
rolfmeijer CreditAttribution: rolfmeijer commentedI 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.
Comment #5
rolfmeijer CreditAttribution: rolfmeijer commentedAdded a patch.
Comment #6
rolfmeijer CreditAttribution: rolfmeijer commentedAs it might be related to #2120055: Trim auto-generated labels, it may be wise to “formalize” this relation.
Comment #7
rolfmeijer CreditAttribution: rolfmeijer commentedComment #8
bforchhammer CreditAttribution: bforchhammer commentedI 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).
Comment #9
bforchhammer CreditAttribution: bforchhammer commentedComment #10
rolfmeijer CreditAttribution: rolfmeijer commentedAh 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.
Comment #11
kukle CreditAttribution: kukle commentedDeleting 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.Comment #12
kukle CreditAttribution: kukle commentedI 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>
Comment #13
BWPanda CreditAttribution: BWPanda commentedHere's a patch that adds an option to strip HTML tags and only strips if the option is enabled.
Comment #14
yogeshmpawarit adds the option to strip HTML tags. patch is good to go.
Comment #15
purushotam.rai CreditAttribution: purushotam.rai at QED42 commentedComment #17
purushotam.rai CreditAttribution: purushotam.rai at QED42 commentedComment #18
purushotam.rai CreditAttribution: purushotam.rai at QED42 commented