I'm trying to get the page title working...I've tried to incorporate the suggested code into my template.php file. I get no errors, but the page title I've defined doesn't show up either...

<?php
function _phptemplate_variables($hook, $variables) {
  // Load the node region only if we're not in a teaser view.
  if ($hook == 'node' && !$vars['teaser']) {
    // Load region content assigned via blocks.
    foreach (array('inline1') as $region) {
      	$variables[$region] = theme('blocks', $region);
    }
  if ($hook == 'page') {
    	$variables['head_title'] = page_title_page_get_title();
  }
  }
  return $variables;
}
?>

Comments

niklp’s picture

  • Install the module
  • Check you have the module enabled
  • Check your database tables exist
  • Edit your template.php file:
    • Check there is not already a _phptemplate_variables() function - if there is, you will be wanting to put the relevant code in this somewhere
    • Add the code - I might suggest (with my limited knowledge of theming) that you rename "$variables" to "$vars" as this seems to be the norm - I am unsure (and unconvinced that this is an issue), but it is possible you might be overriding the theme function incorrectly because of this?
    • Save the file (natch)
  • Edit one of your nodes and add a page title in the relevant form field
  • Save and view - this *should* work...
  • If not you could always try adding the function call at the page.tpl.php level, as suggested in the README
  • Sorry if this list is not very helpful...!
piggybank’s picture

Well, I'm pleased to say I found the problem...it was with my code and how I incorporated the page_title into the already existing _phptemplate_variables() function.

Here's my updated code that IS working:

<?php
function _phptemplate_variables($hook, $vars) {
  // Load the node region only if we're not in a teaser view.
  if ($hook == 'node' && !$vars['teaser']) {
    // Load region content assigned via blocks.
    foreach (array('inline1') as $region) {
      	$vars[$region] = theme('blocks', $region);
    }
	}
  if ($hook == 'page') {
    	$vars['head_title'] = page_title_page_get_title();
  }
  return $vars;
}
?>

This is an example of how to incorporate the necessary code for page_title into your template.php file when there's already an existing function _phptemplate_.

Thanks,

Scott Gingrich

Jolla00’s picture

I've spent several hours trying to get this page title module to work. The object of this is to be able to set all my page titles individually when I create the content. I hope this is the easiest way of achieving this.

Anyway, with my template came no template.php file so I used the one included. When the template.php file has been uploaded to the server and I try to reach my drupal installation from a web browser this is all that I get:

Fatal error: Cannot redeclare _phptemplate_variables() (previously declared in /mounted-storage/home16a/sub001/sc18002-DHRZ/www/Joel/sparportalen.se/drupal/themes/arcmateria/template.php:2) in /mounted-storage/home16a/sub001/sc18002-DHRZ/www/Joel/sparportalen.se/drupal/themes/arcmateria/page.tpl.php on line 6

I can't understand where _phptemplate_variables() can have been declared before. Is the script looping?

I would really appreciate help with this!

niklp’s picture

That seems strange to me, although I'm no expert...

I don't *believe* that any declaration of that function in your theme would cause that error, unless it is already declared somewhere in your theme. Have you checked through the template.php file for existing declarations of the function? There is frequently one already in existence. If not you could check the other files, but it seems unlikely...

Sorry if this isn't helpful.

johnalbin’s picture

Status: Active » Fixed

From your error message, you have declared _phptemplate_variables() in both template.php and page.tpl.php. Remove the declaration from page.tpl.php.

dries’s picture

Status: Fixed » Closed (fixed)
yogayak’s picture

Assigned: Unassigned » yogayak
Priority: Critical » Normal
Status: Closed (fixed) » Active

I am using the garland theme and have tried many different locations for the link_page code to go into. But I keep gettings errors. The code looks different than the above. Can anybody spot where I should insert the code? I'm onling posting part of the template file as it is quite large.

/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars) {
if ($hook == 'page') {

if ($secondary = menu_secondary_local_tasks()) {
$output = '';
$output .= "

    \n". $secondary ."

\n";
$vars['tabs2'] = $output;
}

// Hook into color.module
if (module_exists('color')) {
_color_page_alter($vars);
}
return $vars;
}
return array();
}

johnalbin’s picture

Assigned: yogayak » johnalbin
Status: Active » Closed (fixed)

Hi Michel,

This is the bug reporting queue of the page_title module. If you need support on your template.php file, please head over to the support forums: http://drupal.org/forum/3

- John

yogayak’s picture

I've posted my Garland problem to http://drupal.org/node/152839

John, did I not post to the Issues category not the bugs? If all Garland users have this problem I would consider it an issue. But I trust your judgement.

gurukripa’s picture

I want this to work with book pages and other pages too..is this possible for things like Story/blog also ?

I tried making this work..by adding in my template.php but it doesnt happen. I am using Fancy theme with Drupal 5.1

Here's the template.php Kindly help me with the corrected code for this. Thanks.


function fancy_navlinks($links) {
  $output = '';

  if (count($links) > 0) {
    $output = '<ul>';

       $i = 1;

    foreach ($links as $key => $link) {
      $class = '';

// Automatically add a current LI class ='current' to active link
      if ( stristr($key, 'active') ){
        $class = ' class="current"';
       }


      $output .= '<li id="primary-link-'.$i.'"' .  $class .' >';

      // Is the title HTML?
      $html = isset($link['html']) && $link['html'];

      // Initialize fragment and query variables.
      $link['query'] = isset($link['query']) ? $link['query'] : NULL;
      $link['fragment'] = isset($link['fragment']) ? $link['fragment'] : NULL;

      if (isset($link['href'])) {
        $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
      }
      else if ($link['title']) {
        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }

  return $output;
}
// $Id: template.php,v 1.7 2006/05/11 18:17:29 ayman Exp $
function _phptemplate_variables($hook, $vars) {
  static $is_forum;
  $variables = array();
  if (!isset($is_forum)) {
    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '') {
      $nid = arg(1);
    }
    if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
      $nid = arg(2);
    }
    if ($nid) {
      $node = node_load(array('nid' => $nid));
    }
    $is_forum = ($node && $node->type == 'forum');
    _is_forum($is_forum);
  }
  if ($is_forum) {
    switch ($hook) {
      case 'comment' :
        $variables['template_file'] = 'node-forum';
        $variables['row_class'] = _row_class();
        $variables['name'] = $vars['author'];
        $variables['userid'] = $vars['comment']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['comment']->uid);
        $variables['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['comment']->uid);
        $variables['posts'] = $posts ? $posts : 0;
        $variables['submitted'] = format_date($vars['comment']->timestamp);
        $subject = $vars['comment']->subject;
        $variables['title'] = empty($subject) ? '&nbsp' : $subject;
        $variables['content'] = $vars['comment']->comment;
        $variables['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
        break;
      case 'node' :
        $variables['row_class'] = _row_class();
        $variables['userid']=$vars['node']->uid;
        $joined = module_invoke('flatforum', 'get_created', $vars['node']->uid);
        $variables['joined'] = $joined ? format_date($joined, 'custom', 'Y-m-d') : '';
        $posts = module_invoke('flatforum', 'get', $vars['node']->uid);
        $variables['posts'] = $posts ? $posts : 0;
        $variables['title'] = empty($vars['title']) ? '&nbsp' : $vars['title'];
        $variables['content'] = $vars['node']->body;
        $variables['links'] = empty($vars['links']) ? '&nbsp' : $vars['links'];
        break;
    }
  }
  return $variables;
}
function _row_class() {
  static $forum_row = TRUE;
  $forum_row = !$forum_row;
  return $forum_row ? 'odd' : 'even';
}
function _is_forum($arg = NULL) {
  static $is_forum = FALSE;
  if ($arg) {
    $is_forum = $arg;
  }
  return $is_forum;
}
/**
* Catch the theme_profile_profile function, and redirect through the template api
*/
function phptemplate_user_profile($user, $fields = array()) {
  // Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
  // will be assigned within your template.
  /* potential need for other code to extract field info */
return _phptemplate_callback('user_profile', array('user' => $user, 'fields' => $fields));
}

  $vars = array();
  if ($hook == 'page') {

    // These are the only important lines
    if (module_exists('page_title')) {
      $vars['head_title'] = page_title_page_get_title();
    }

  }
  return $vars;
gurukripa’s picture

Status: Closed (fixed) » Active

sorry forgot to make it active...and just checked and found that i am using 5.x-1.1
kindly advise
thanks

johnalbin’s picture

Title: Incorporate into template.php » Trouble incorporating into template.php

Mahaprabhu, in Fancy theme’s template.php file, find the _phptemplate_variables() function and add the following lines just before return $variables;.

  if ($hook == 'page') {
    if (module_exists('page_title')) {
      $variables['head_title'] = page_title_page_get_title();
    }
  }
nicholasthompson’s picture

Status: Active » Fixed

Closed due to inactivity...

Anonymous’s picture

Status: Fixed » Closed (fixed)