Hello,
Where is the best place for a module/theme to edit the node title? I would like to prepend the node type to the title input by the user.
I have custom node types created with hook_*(). I tried to set $node->title in hook_view(), but it doesn't affect anything.
Changing the node title at the theme level seems a bit clumsy: too much php and sql queries would be needed there.
Where do you handle this?
Thanks,
Augustin.
On Thursday 13 September 2007 16:30, Augustin (Beginner) wrote:
Where is the best place for a module/theme to edit the node title? I would like to prepend the node type to the title input by the user.
I have custom node types created with hook_*(). I tried to set $node->title in hook_view(), but it doesn't affect anything.
Well. I finally used the following solution:
I added an item in the node object within hook_load(): $node->title_prepend = "what I want here";
and then at the theme level:
<?php if ($node->title_prepend): print '<span class="node-label">'. $node->title_prepend .' </span>'; endif; ?>
It works. If there is a better solution, I'd be happy to hear about it.
thanks,
Augustin.
Quoting "Augustin (Beginner)" drupal.beginner@wechange.org:
<?php if ($node->title_prepend): print '<span class="node-label">'. $node->title_prepend .' </span>'; endif; ?>
Don't you need to protect against the non-existence of $node->title_prepend or is it guaranteed to be present at this point?
<code> <?php if (isset($node->title_prepend)): print '<span class="node-label">'. $node->title_prepend .' </span>'; endif; ?> </code>
And you want to prettify this code.
Earnie -- http://for-my-kids.com/ -- http://give-me-an-offer.com/
On Thursday 13 September 2007 19:49, Earnie Boyd wrote:
Quoting "Augustin (Beginner)" drupal.beginner@wechange.org:
<?php if ($node->title_prepend): print '<span class="node-label">'. $node->title_prepend .' </span>'; endif; ?>
Don't you need to protect against the non-existence of $node->title_prepend or is it guaranteed to be present at this point?
You are right. I am supposed to use isset().
<code> <?php if (isset($node->title_prepend)): print '<span class="node-label">'. $node->title_prepend .' </span>'; endif; ?> </code>
And you want to prettify this code.
Yes. :) I just copied the coding style in Garland's page.tpl.
Thanks,
Augustin.
On Sep 14, 2007, at 8:56 AM, Augustin (Beginner) wrote:
On Thursday 13 September 2007 19:49, Earnie Boyd wrote:
Quoting "Augustin (Beginner)" drupal.beginner@wechange.org:
<?php if ($node->title_prepend): print '<span class="node-label">'. $node->title_prepend .' </span>'; endif; ?>
Don't you need to protect against the non-existence of $node->title_prepend or is it guaranteed to be present at this point?
You are right. I am supposed to use isset().
<code> <?php if (isset($node->title_prepend)): print '<span class="node- label">'. $node->title_prepend .' </span>'; endif; ?> </code>
And you want to prettify this code.
Here's a simpler solution (I think) but maybe this approach has been deprecated as it's something I used back in the 4.6 days....
<?php print $node->type ?>
A linked node title then would be something like:
<h2 class="title"><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $node->type ?>: <?php print $title ?></ a></h2>
Laura
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Laura Scott schrieb:
On Sep 14, 2007, at 8:56 AM, Augustin (Beginner) wrote:
On Thursday 13 September 2007 19:49, Earnie Boyd wrote:
Quoting "Augustin (Beginner)" drupal.beginner@wechange.org:
<?php if ($node->title_prepend): print '<span class="node-label">'. $node->title_prepend .' </span>'; endif; ?>
Don't you need to protect against the non-existence of $node->title_prepend or is it guaranteed to be present at this point?
You are right. I am supposed to use isset().
<code> <?php if (isset($node->title_prepend)): print '<span class="node- label">'. $node->title_prepend .' </span>'; endif; ?> </code>
And you want to prettify this code.
Here's a simpler solution (I think) but maybe this approach has been deprecated as it's something I used back in the 4.6 days....
<?php print $node->type ?>
In the 4.6 days we didn't have node types which where named by users in core. Now that we have them, $node->type should be regarded as user input and sanitized on output:
<?php print check_plain($node->type); ?>
Cheers, Ger»yes, it may seem overzealous«hard
On Sep 14, 2007, at 10:18 AM, Gerhard Killesreiter wrote:
In the 4.6 days we didn't have node types which where named by users in core. Now that we have them, $node->type should be regarded as user input and sanitized on output:
<?php print check_plain($node->type); ?>
Cheers, Ger»yes, it may seem overzealous«hard
Duh! Great point! Thank you!
Laura
Isn't node type sanitized on input. (can't have spaces etc? )
Just curious.
Dave
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Gerhard Killesreiter Sent: Friday, September 14, 2007 9:18 AM To: support@drupal.org Subject: Re: [support] The best place to edit the node title?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Laura Scott schrieb:
On Sep 14, 2007, at 8:56 AM, Augustin (Beginner) wrote:
On Thursday 13 September 2007 19:49, Earnie Boyd wrote:
Quoting "Augustin (Beginner)" drupal.beginner@wechange.org:
<?php if ($node->title_prepend): print '<span class="node-label">'. $node->title_prepend .' </span>'; endif; ?>
Don't you need to protect against the non-existence of $node->title_prepend or is it guaranteed to be present at this
point?
You are right. I am supposed to use isset().
<code> <?php if (isset($node->title_prepend)): print '<span class="node- label">'. $node->title_prepend .' </span>'; endif; ?> </code>
And you want to prettify this code.
Here's a simpler solution (I think) but maybe this approach has been deprecated as it's something I used back in the 4.6 days....
<?php print $node->type ?>
In the 4.6 days we didn't have node types which where named by users in core. Now that we have them, $node->type should be regarded as user input and sanitized on output:
<?php print check_plain($node->type); ?>
Cheers, Ger>yes, it may seem overzealous<hard
-- [ Drupal support list | http://lists.drupal.org/ ]
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Metzler, David schrieb:
Isn't node type sanitized on input. (can't have spaces etc? )
It might be, I didn't check. But it is best if people err on the side of caution. Essentially, everything that is a property of an object or an element of an array shouldl be checked when you write a template. A check_plain too many ususally doesn't hurt. And if it does, you'll notice.
Cheers, Gerhard