Community

how do I access [node:title] from template.php

What I am trying to do is change the text of the PDF link from the Print module to read "Case Study: [node:title]" with [node:title] obviously being the title of the current node. I have copied the appropriate function to my template.php file and renamed it. It is getting as far as changing the link text to "Case Study", but the node title part is giving me an error.

The relevant line from the function:
$print_pdf_link_text = filter_xss(variable_get('print_pdf_link_text', t('Case Study').": ".$vars['title']));

and the error:
Notice: Undefined variable: vars in bitcloud_print_pdf_format_link() (line 155 of /home/***/public_html/***/sites/all/themes/bitcloud/template.php).

Obviously $vars['title'] is wrong, but I don't know what to use instead and so far none of my google searches have been successful. I am using Drupal 7, and in case it matters, this is for a Zen subtheme. Any help would be appreciated.

Comments

node_load

If the PDF link is embedded in a node then you can get the node title as follows:

// First check this is a node page being displayed
if (arg(0) == 'node' && is_numeric(arg(1)) {
  // Load the node
$node = node_load(arg(1));
  // Extract the title
  $title = $node->title;
}

Hope this helps

Ed

Thankyou for the reply. But

Thankyou for the reply. But that didn't work for me. Probably something to do with my setup. The PDF link gets output in the Links part of the node - not sure if that makes any difference.
I did actually come up with a workaround. Because the node URLs all follow the pattern "/casestudy/[node:title]" and the PDF links all follow the pattern "/printpdf/casestudy/[node:title]" what I did in the custom node template was:

<a href="<?php print str_replace("casestudy","printpdf/casestudy",$node_url); ?>">Case Study: <?php print $title; ?></a>

Probably horribly inelegant (I'm not a programmer) but it's working for me.
nobody click here