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?

Mohsen Nosratinia
  • 9,844
  • 1
  • 27
  • 52
james6848
  • 1,657
  • 3
  • 25
  • 39
  • 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? – picxelplay Jun 05 '12 at 12:04

3 Answers3

7

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

Sk8erPeter
  • 6,899
  • 9
  • 48
  • 67
Rajat Gusain
  • 71
  • 1
  • 1
  • drupal_get_title() doesn't work when _cache block_ is enabled under performance settings. Any other solution? – kiranking Nov 17 '14 at 10:48
  • `drupal_get_title()` is working with *cache block* when the appropriate cache setting for the block is set to *Do not cache* – eapo Apr 18 '16 at 21:32
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
}
Tomasz Struczyński
  • 3,273
  • 23
  • 28
  • 1
    drupal.api already has function for it: $node = menu_get_object(); print $node->title; – Nikit Mar 19 '10 at 00:21
2

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

Sk8erPeter
  • 6,899
  • 9
  • 48
  • 67
nenne
  • 165
  • 2
  • 9