HTML in node titles for D5
Hi all, I need to enable simple HTML styling on node titles. I believe this would be rather common on news sites and similar. Is there any correct (or as little disruptive as possible) method to implement that? How much of core hackery will be required? I will not be able to switch to D6, until a significant amount of contrib I am using will be available for D6.. Thanks, -- Yuval Hager [T] +972-77-341-4155 [@] yuval@avramzon.net
You rather keep all your titles presented in the same way, you style h2 or create new node-x.tpl.php files with new styles. And if you really need the html in your titles use cck to create new title field and use autotile module to hide original title field. Please note $node->title is a varchar(255) so you might run out of space for html tags there. PS.This is rather support not devel question. Mac On Jan 17, 2008 10:23 AM, Yuval Hager <yuval@avramzon.net> wrote:
Hi all,
I need to enable simple HTML styling on node titles. I believe this would be rather common on news sites and similar. Is there any correct (or as little disruptive as possible) method to implement that? How much of core hackery will be required?
I will not be able to switch to D6, until a significant amount of contrib I am using will be available for D6..
Thanks,
-- Yuval Hager [T] +972-77-341-4155 [@] yuval@avramzon.net
-- - kindest regards Maciej Perlinski maciej.perlinski@meant4.com http://www.meant4.com
CSS could to this. If you need it to change on all the node titles sytle the title. If you need it just on specific titles use a setup like garland. #node-12 h2 { some css } Just change the number to the nid you are editing. I would suggest doing this type of change in the theme/presentation layer. Try the support mailing list. You might get a better response of ideas. Matt Quoting Maciej Perlinski <maciej.perlinski@gmail.com>:
You rather keep all your titles presented in the same way, you style h2 or create new node-x.tpl.php files with new styles. And if you really need the html in your titles use cck to create new title field and use autotile module to hide original title field.
Please note $node->title is a varchar(255) so you might run out of space for html tags there.
PS.This is rather support not devel question.
Mac
On Jan 17, 2008 10:23 AM, Yuval Hager <yuval@avramzon.net> wrote:
Hi all,
I need to enable simple HTML styling on node titles. I believe this would be rather common on news sites and similar. Is there any correct (or as little disruptive as possible) method to implement that? How much of core hackery will be required?
I will not be able to switch to D6, until a significant amount of contrib I am using will be available for D6..
Thanks,
-- Yuval Hager [T] +972-77-341-4155 [@] yuval@avramzon.net
-- - kindest regards Maciej Perlinski maciej.perlinski@meant4.com http://www.meant4.com
On Thursday 17 January 2008, Maciej Perlinski wrote:
You rather keep all your titles presented in the same way, you style h2 or create new node-x.tpl.php files with new styles. And if you really need the html in your titles use cck to create new title field and use autotile module to hide original title field.
Exactly, I need HTML *inside* the titles. Your idea sounds simple enough - but don't I lose anything by not really using the core title field?
Please note $node->title is a varchar(255) so you might run out of space for html tags there.
PS.This is rather support not devel question.
Right. I was more thinking in terms of *core* title field, that's why I posted it here.. Sorry.. --y
Yuval wrote:
Exactly, I need HTML *inside* the titles.
Your idea sounds simple enough - but don't I lose anything by not really using the core title field?
You lose some performance, but afaik no more than any other cck field + small module so it should be quite negligible overall. The New York Observer site used html inside titles, and gave some information here: http://drupal.org/node/141187, although it required a core hack iirc. Automatic node titles has come up as a solution quite often.
well if your rally need you can have your original title filed be filled up with the plain text title made created from rich text title field created in cck. Well i guess you have the answer for your question: - do it in css+theme (presentation layer) google: MVC wikipedia for more info - you can use cck + autotitle field the solution is there you have to decide what to use based on the requirements... Mac On Jan 17, 2008 3:58 PM, catch <catch56@googlemail.com> wrote:
Yuval wrote:
Exactly, I need HTML *inside* the titles.
Your idea sounds simple enough - but don't I lose anything by not really using the core title field?
You lose some performance, but afaik no more than any other cck field + small module so it should be quite negligible overall. The New York Observer site used html inside titles, and gave some information here: http://drupal.org/node/141187, although it required a core hack iirc. Automatic node titles has come up as a solution quite often.
-- - kindest regards Maciej Perlinski maciej.perlinski@meant4.com http://www.meant4.com
If you are in a situation where you have to have html in the title (say in just part of it where you can't get there with CSS) I've used cck + auto title. Having the title automatically created from a cck field can let you still use is in view block listings, RSS feeds, and other places fairly easily. Matt Quoting Maciej Perlinski <maciej.perlinski@gmail.com>:
well if your rally need you can have your original title filed be filled up with the plain text title made created from rich text title field created in cck.
Well i guess you have the answer for your question: - do it in css+theme (presentation layer) google: MVC wikipedia for more info - you can use cck + autotitle field
the solution is there you have to decide what to use based on the requirements...
Mac
On Jan 17, 2008 3:58 PM, catch <catch56@googlemail.com> wrote:
Yuval wrote:
Exactly, I need HTML *inside* the titles.
Your idea sounds simple enough - but don't I lose anything by not really using the core title field?
You lose some performance, but afaik no more than any other cck field + small module so it should be quite negligible overall. The New York Observer site used html inside titles, and gave some information here: http://drupal.org/node/141187, although it required a core hack iirc. Automatic node titles has come up as a solution quite often.
-- - kindest regards Maciej Perlinski maciej.perlinski@meant4.com http://www.meant4.com
I was able to do this back in 4.7 with Views. The titles for blocks that were generated by views allowed HTML tags, so I was able to add divs in them and the themer was able to style it using CSS. It was a bug at the time but did exactly what the client wanted. I think now things get passed through check_plain() so it is no longer the case, but have not checked recently. -- Khalid M. Baheyeldin 2bits.com, Inc. http://2bits.com Drupal optimization, development, customization and consulting.
The major thing is to explain that titles should rather be the same quick info about simplest solution, in your node-x.tpl.php check if the title is set and if it is not empty (i got suprised when one of my customers just pressed space which gave him as an outcome empty tiltle D5 and validation went through btw. i m not sure if its not a bug) and if the title is empty in the meaning i said above it has just whitespace don't show <h2></h2> tags than customer can create title and style the way he wants... Mac On Jan 17, 2008 4:10 PM, Khalid Baheyeldin <kb@2bits.com> wrote:
I was able to do this back in 4.7 with Views. The titles for blocks that were generated by views allowed HTML tags, so I was able to add divs in them and the themer was able to style it using CSS.
It was a bug at the time but did exactly what the client wanted.
I think now things get passed through check_plain() so it is no longer the case, but have not checked recently. -- Khalid M. Baheyeldin 2bits.com, Inc. http://2bits.com Drupal optimization, development, customization and consulting.
-- - kindest regards Maciej Perlinski maciej.perlinski@meant4.com http://www.meant4.com
On Thursday 17 January 2008, catch wrote:
Yuval wrote:
Exactly, I need HTML *inside* the titles.
Your idea sounds simple enough - but don't I lose anything by not really
using
the core title field?
You lose some performance, but afaik no more than any other cck field + small module so it should be quite negligible overall. The New York Observer site used html inside titles, and gave some information here: http://drupal.org/node/141187, although it required a core hack iirc. Automatic node titles has come up as a solution quite often.
Yes, I guess the right way would be to replace the title with a CCK field + auto_nodetitle.module. For the sake of archives, I would like to clarify the original question - it had nothing to do with theming or css - just with HTML tags in a title, like - 'Hello <em>world</em>'. I am just curious why the nyobserver site hacked core and not used a cck field.. (reading through the comments in that thread I see some reference to this challenge - http://drupal.org/nyobserver#comment-228510) -- Yuval Hager [T] +972-77-341-4155 [@] yuval@avramzon.net
Quoting Yuval Hager <yuval@avramzon.net>:
I am just curious why the nyobserver site hacked core and not used a cck field.. (reading through the comments in that thread I see some reference to this challenge - http://drupal.org/nyobserver#comment-228510)
I don't know, I can guess they didn't want to add the extra overhead. The core title filtered through the check_plain function which removes html in the title. You could write a hook_nodeapi [1] function in a custom module to repopulate it before it is saved to the DB. [1] http://api.drupal.org/api/function/hook_nodeapi/5 Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
Yes well i guess thats why we have nodeapi :) On Jan 17, 2008 5:27 PM, Earnie Boyd <earnie@users.sourceforge.net> wrote:
Quoting Yuval Hager <yuval@avramzon.net>:
I am just curious why the nyobserver site hacked core and not used a cck field.. (reading through the comments in that thread I see some reference to this challenge - http://drupal.org/nyobserver#comment-228510)
I don't know, I can guess they didn't want to add the extra overhead. The core title filtered through the check_plain function which removes html in the title. You could write a hook_nodeapi [1] function in a custom module to repopulate it before it is saved to the DB.
[1] http://api.drupal.org/api/function/hook_nodeapi/5
Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
-- - kindest regards Maciej Perlinski maciej.perlinski@meant4.com http://www.meant4.com
On Jan 17, 2008, at 8:27 AM, Earnie Boyd wrote:
You could write a hook_nodeapi [1] function in a custom module to repopulate it before it is saved to the DB.
That doesn't help you at all. Drupal filters on *output*. You can get "Hello <em>world</em>" into the title field in your DB directly when you create or edit the node -- you don't need nodeapi for this. The only way to get "Hello <em>world</em>" to be *output* as HTML when the node is rendered is to hack *a lot* of places in core to remove the security filtering in place to prevent XSS attacks, which is generally a very bad idea for all sorts of reasons. If you do that, then you have to trust every user with permission to create nodes that they're not going to input "Hello <script>badness10000</ script> world" as node titles. Cheers, -Derek (dww)
Since drupal stores what you input (including the html), as Derek points out, all you need to do it change the output themeing to allow html to pass. You could do this by creating the function mythemename_node in your template.php file, making this a copy of the function of phptemplate_node, and changing 'title' => check_plain($node->title) to 'title' => check_markup($node->title, 2) Change the 2 to the input format you want to use on this field. This lets you keep filtering on it but pass html. The problem that will come up with this, now that I think about this is places like the page title in the browser. That is passed through check_plain so and em tag will show up with the words em. This is something that might be best done with cck + automatic titles. It would be less work in development. Matt Quoting Derek Wright <drupal@dwwright.net>:
On Jan 17, 2008, at 8:27 AM, Earnie Boyd wrote:
You could write a hook_nodeapi [1] function in a custom module to repopulate it before it is saved to the DB.
That doesn't help you at all. Drupal filters on *output*. You can get "Hello <em>world</em>" into the title field in your DB directly when you create or edit the node -- you don't need nodeapi for this.
The only way to get "Hello <em>world</em>" to be *output* as HTML when the node is rendered is to hack *a lot* of places in core to remove the security filtering in place to prevent XSS attacks, which is generally a very bad idea for all sorts of reasons. If you do that, then you have to trust every user with permission to create nodes that they're not going to input "Hello <script>badness10000</script> world" as node titles.
Cheers, -Derek (dww)
try it and you will see. titles in rss reeds and emails will have markup in them, for example. and many places run check_plain($node->title) before output.
I am just curious why the nyobserver site hacked core and not used a cck field.. (reading through the comments in that thread I see some reference to this challenge - http://drupal.org/nyobserver#comment-228510)
On Thursday 17 January 2008, Moshe Weitzman wrote:
try it and you will see. titles in rss reeds and emails will have markup in them, for example. and many places run check_plain($node->title) before output.
I believe hacking core should be the last option in terms of manageability, so I've opened an issue on this - http://drupal.org/node/211475. Patches are welcome. --y
I am just curious why the nyobserver site hacked core and not used a cck field.. (reading through the comments in that thread I see some reference to this challenge - http://drupal.org/nyobserver#comment-228510)
-- Yuval Hager [T] +972-77-341-4155 [@] yuval@avramzon.net
Please tell me if this is a bad idea, but how about this as a solution: If you are only interested in minimal markup, like the ability to use the <em> tag, what about using a special character to indicate it in the node title, and then processing the title at the theme layer (for example with a regular expression) to convert the characters into tags. For example, you could use Hello *World!* as the node title and then convert this with a simple regular expression to Hello <em>World!</em> when the node is rendered. This would have the added advantage of keep clean the RSS feed from the node. It would also be much shorter than putting markup in the title, bearing in mind the 255 char limit. Would this be classified as a hack? On Jan 18, 2008 1:37 AM, Yuval Hager <yuval@avramzon.net> wrote:
On Thursday 17 January 2008, Moshe Weitzman wrote:
try it and you will see. titles in rss reeds and emails will have markup in them, for example. and many places run check_plain($node->title) before output.
I believe hacking core should be the last option in terms of manageability, so I've opened an issue on this - http://drupal.org/node/211475. Patches are welcome.
--y
I am just curious why the nyobserver site hacked core and not used a cck field.. (reading through the comments in that thread I see some reference to this challenge - http://drupal.org/nyobserver#comment-228510)
-- Yuval Hager [T] +972-77-341-4155 [@] yuval@avramzon.net
On Sunday 20 January 2008, Andrew ft wrote:
Please tell me if this is a bad idea, but how about this as a solution: If you are only interested in minimal markup, like the ability to use the <em> tag, what about using a special character to indicate it in the node title, and then processing the title at the theme layer (for example with a regular expression) to convert the characters into tags. For example, you could use Hello *World!* as the node title and then convert this with a simple regular expression to Hello <em>World!</em> when the node is rendered. This would have the added advantage of keep clean the RSS feed from the node. It would also be much shorter than putting markup in the title, bearing in mind the 255 char limit. Would this be classified as a hack?
That's a very good idea! It has the advantage that in all places that output check_plain($node->title) will show a reasonable string after all. As long as the required markup is limited - this is the most elegant solution I've seen! Thanks, --yuval
I also need this but what I need is a link. Perhaps [text:url] or something similar could be changed to <a href="url">text</a>. Is this secure, given that text:url has been though checkplain? -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Yuval Hager Sent: Sunday, January 20, 2008 12:12 AM To: development@drupal.org Subject: Re: [development] HTML in node titles for D5 On Sunday 20 January 2008, Andrew ft wrote:
Please tell me if this is a bad idea, but how about this as a solution: If you are only interested in minimal markup, like the ability to use the <em> tag, what about using a special character to indicate it in the node title, and then processing the title at the theme layer (for example with a regular expression) to convert the characters into tags. For example, you could use Hello *World!* as the node title and then convert this with a simple regular expression to Hello <em>World!</em> when the node is rendered. This would have the added advantage of keep clean the RSS feed from the node. It would also be much shorter than putting markup in the title, bearing in mind the 255 char limit. Would this be classified as a hack?
That's a very good idea! It has the advantage that in all places that output check_plain($node->title) will show a reasonable string after all. As long as the required markup is limited - this is the most elegant solution I've seen! Thanks, --yuval No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.7/1233 - Release Date: 1/19/2008 6:37 PM No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.7/1233 - Release Date: 1/19/2008 6:37 PM
There is an added complication with a link in a node in that when the node is presented as a teaser, it will already be a link to the full node page. Because of this we can only implement the hyperlinks when the browser is on the full node page. If we assume the simplest situation where the *whole node* is a link, I would suggest using "[" and "]" as delimiters, something like this: original node: *text of node [url] *on node page after processing: *<a href="url">text of node </a>* on teaser page after processing:* text of node* In a more complex situation where you want arbitrary words in the node to be hyperlinked, you can extend the sytax slightly with something like: original node: *This is my node [with linked text:url] in it* on node page after processing: *This is my node <a href="url">with linked text</a> in it* on teaser page after processing: *This is my node with linked text in it* I haven't yet written the specific regular expressions you would need for the above syntax. Sometimes it is best to adjust the sytax to make it easy to write the regex. On Jan 20, 2008 9:40 AM, Walt Daniels <wdlists@optonline.net> wrote:
I also need this but what I need is a link. Perhaps [text:url] or something similar could be changed to <a href="url">text</a>. Is this secure, given that text:url has been though checkplain?
-----Original Message----- From: development-bounces@drupal.org [mailto: development-bounces@drupal.org] On Behalf Of Yuval Hager Sent: Sunday, January 20, 2008 12:12 AM To: development@drupal.org Subject: Re: [development] HTML in node titles for D5
On Sunday 20 January 2008, Andrew ft wrote:
Please tell me if this is a bad idea, but how about this as a solution: If you are only interested in minimal markup, like the ability to use the <em> tag, what about using a special character to indicate it in the node title, and then processing the title at the theme layer (for example with a regular expression) to convert the characters into tags. For example, you could use Hello *World!* as the node title and then convert this with a simple regular expression to Hello <em>World!</em> when the node is rendered. This would have the added advantage of keep clean the RSS feed from the node. It would also be much shorter than putting markup in the title, bearing in mind the 255 char limit. Would this be classified as a hack?
That's a very good idea! It has the advantage that in all places that output
check_plain($node->title) will show a reasonable string after all. As long as the required markup is limited - this is the most elegant solution I've seen!
Thanks,
--yuval
No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.7/1233 - Release Date: 1/19/2008 6:37 PM
No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.7/1233 - Release Date: 1/19/2008 6:37 PM
You might check to see if one of the markup engines (Markdown, Texy, Textile, etc) can be made to work in this context. Ricky On Jan 20, 2008, at 9:40 AM, Walt Daniels wrote:
I also need this but what I need is a link. Perhaps [text:url] or something similar could be changed to <a href="url">text</a>. Is this secure, given that text:url has been though checkplain?
-----Original Message----- From: development-bounces@drupal.org [mailto:development- bounces@drupal.org] On Behalf Of Yuval Hager Sent: Sunday, January 20, 2008 12:12 AM To: development@drupal.org Subject: Re: [development] HTML in node titles for D5
On Sunday 20 January 2008, Andrew ft wrote:
Please tell me if this is a bad idea, but how about this as a solution: If you are only interested in minimal markup, like the ability to use the <em> tag, what about using a special character to indicate it in the node title, and then processing the title at the theme layer (for example with a regular expression) to convert the characters into tags. For example, you could use Hello *World!* as the node title and then convert this with a simple regular expression to Hello <em>World!</ em> when the node is rendered. This would have the added advantage of keep clean the RSS feed from the node. It would also be much shorter than putting markup in the title, bearing in mind the 255 char limit. Would this be classified as a hack?
That's a very good idea! It has the advantage that in all places that output
check_plain($node->title) will show a reasonable string after all. As long as the required markup is limited - this is the most elegant solution I've seen!
Thanks,
--yuval
No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.7/1233 - Release Date: 1/19/2008 6:37 PM
No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.7/1233 - Release Date: 1/19/2008 6:37 PM
The information transmitted in this electronic communication is intended only for the person or entity to whom it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this information in error, please contact the Compliance HelpLine at 800-856-1983 and properly dispose of this information.
participants (12)
-
Andrew Fountain -
Andrew ft -
catch -
Derek Wright -
Earnie Boyd -
Khalid Baheyeldin -
Maciej Perlinski -
matt@mattfarina.com -
Moshe Weitzman -
Richard Morse -
Walt Daniels -
Yuval Hager