Drupal - displaying the title of the node within a block
Asked Answered
P

3

7

I'm needing to dynamically display the title of a node within a block. I would have thought this would be simple, but all the code snippets I've tried don't seem to work (e.g. <?php print $node->title; ?> )

I've checked and tested that the PHP input format is on and working with other PHP bits and bobs, and everything seems OK.

Any ideas?

Powys answered 18/3, 2010 at 12:54 Comment(1)
Are you wanting to render the page title in a block, thus having the page title display once? Or to have the normal page title display, as well as having the page title outputted a second time on the page?Paulsen
H
6

I thik this link might be of help:

http://www.g-loaded.eu/2009/05/07/drupal-tip-list-a-nodes-taxonomy-terms-inside-a-block/

Based on it:

if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
    $node = node_load(arg(1));
    echo $node->title
}
Holotype answered 18/3, 2010 at 13:8 Comment(1)
drupal.api already has function for it: $node = menu_get_object(); print $node->title;Maurer
A
7

Use drupal_get_title() for getting the title of the current page.

Antimony answered 2/4, 2012 at 12:2 Comment(2)
drupal_get_title() doesn't work when cache block is enabled under performance settings. Any other solution?Burning
drupal_get_title() is working with cache block when the appropriate cache setting for the block is set to Do not cacheAppalachia
H
6

I thik this link might be of help:

http://www.g-loaded.eu/2009/05/07/drupal-tip-list-a-nodes-taxonomy-terms-inside-a-block/

Based on it:

if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
    $node = node_load(arg(1));
    echo $node->title
}
Holotype answered 18/3, 2010 at 13:8 Comment(1)
drupal.api already has function for it: $node = menu_get_object(); print $node->title;Maurer
C
2

There is also the option to use the Views module for this.

Colwin answered 19/3, 2010 at 9:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.