Get $node variable in html.tpl.php - Drupal 7 - Printable Version +- 0Day Forums (https://0day.red) +-- Forum: Coding (https://0day.red/Forum-Coding) +--- Forum: CMS (https://0day.red/Forum-CMS) +---- Forum: Drupal (https://0day.red/Forum-Drupal) +---- Thread: Get $node variable in html.tpl.php - Drupal 7 (/Thread-Get-node-variable-in-html-tpl-php-Drupal-7) |
Get $node variable in html.tpl.php - Drupal 7 - hammilyfbwb - 07-27-2023 I'm trying to allow users to update head titles and meta descriptions for each page. I thought that an easy way to achieve this would be to add a field to the 'Basic page' content type for the page title, then check if that field is not empty in html.tpl.php and if it is not, override $head_title with this user-defined value. However, it appears that the $node variable is not available in html.tpl.php. Can anyone suggest a way for me to make this data available in this template file, or alternatively, alter $head_title before it is sent to html.tpl.php? Thanks for reading. RE: Get $node variable in html.tpl.php - Drupal 7 - mauriciofpiql - 07-27-2023 Taken in part from this thread that I found: [To see links please register here] ...In your `template.php`, you can do the following: function yourtheme_preprocess_html(&$variables) { // If on an individual node page, add the node type to body classes. if ($node = menu_get_object()) { $variables['head_title'] = $node-> // find your cck field here } } RE: Get $node variable in html.tpl.php - Drupal 7 - ikon922562 - 07-27-2023 Bit messy, but would work: if(arg(0) == 'node' && !empty(arg(1))) { $node = node_load(arg(1)); } However, you might prefer [To see links please register here] (an interrim module until the full[To see links please register here] is finished). |