Hey,

I'm pretty new to drupal, and was advised to get the latest version 7 to do what i needed it to do. I am adding an if clause to the title section of the page.tpl.php so if the node type is image then no title is printed. It seems to work, the title is only visible on pages that are not images, but I keep getting the error message:

Notice: Undefined variable: node in include() (line 125 of /sites/all/themes/angel/templates/page.tpl.php).

Is it a bug, or am I doing something incorrectly. code line is:

<?php if ($node->type !== 'image'): print '<h1 class="title" id="page-title">'; ?> <?php print $title; endif; ?></h1>
Many thanks for any help in advance.

Comments

danillonunes’s picture

Some pages are not related to any node (like the user/login page, for example), so the variable $node is not defined.

Try:

if ($node && $node->type !== 'image'):

agbwatson’s picture

Title: Notice: Undefined variable: node in include() » Thanks for the quick reply

Tried that, cleared all the cache, but still got an undefined variable error message. For now, I've got round it by removing the title from the page.tpl.php and adding my own field for when I need it.

Thanks very much for the info, I'm certain I'll need that code as I delve further into customizing!

danillonunes’s picture

Title: Thanks for the quick reply » Notice: Undefined variable: node in include()
Category: bug » support

agbwatson,

so try instead:

 if (isset($node) && $node->type !== 'image'): 

Or you can do it changing the theme_preprocess_page into template.php (read the "CREATE OR MODIFY VARIABLES FOR YOUR THEME" instructions in your template.php file for more details. That's way is better, IMHO, because you keep the logic out of the .tpl files.

function yourtheme_preprocess_page(&$vars, $hook) {
  if (isset($vars['node']) {
    switch ($vars['node']->type) {
      case 'image':
        $vars['title'] = '';
        break;
    }
  }
}

Also, note that this is not really a Zen bug.

agbwatson’s picture

Changing in the template.php worked like a charm. Thanks so much for the help.

I put this in the bug area, as I believed at the time it was. That's the problem with not knowing quite enough about php yet...but learning. Thanks again.

agbwatson’s picture

Status: Active » Closed (fixed)
alex.87’s picture

Component: PHP Code » layout.css

Hey i have similar issue like agbwatson. I use this code to get my widgets in sidebar:

<?php if (count($node->field_adds) != 0)
      {
          foreach($node->field_adds['und'] as $key => $value)
    {        
        $nid = $value['nid']; 
        $mywidget = node_view(node_load($nid));
        print drupal_render($mywidget);
    }    
      }
       ?>

And i keep getting error
Notice: Undefined property: stdClass::$field_adds in include() (line 69 ofhome/dev2fabr/public_html/QPQ/sites/all/themes/qpq/page.tpl.php).

any sugestions?

artwreck’s picture

Try

<?php
if (!empty($node) && $node->type !== 'image'):
?>
knalstaaf’s picture

Issue summary: View changes

I must say this code from #3 works (added a missing bracket):

function yourtheme_preprocess_page(&$vars, $hook) {
    if (isset($vars['node'])) {
        switch ($vars['node']->type) {
            case 'image':
                $vars['title'] = '';
                break;
        }
    }
}

I wouldn't recommend the method in #7 or the short line in #3. Both removed the page title of my View page displays as well.

knalstaaf’s picture

Project: Zen »
Version: 7.x-3.x-dev »
Component: layout.css » Code
stewit’s picture

I found that the short code from #3 worked for me, as I was trying to load a different template file if it was a forum page.

This is what I used for those in the future that require overriding all the forum pages and articles;

<?php
if (isset($node) && $node->type == 'forum') {
  include('page--forum.tpl.php');
  return;
}
?>

Placed this in my page.tpl.php file. Works fine for me.

batuka’s picture

Pls I have a similar problem, I'm getting this error:

Notice: Undefined variable: image in include() (line 1 of /Applications/mampstack/apache2/htdocs/xxxx/sites/all/modules/views_bootstrap/templates/carousel/views-bootstrap-carousel-plugin-rows.tpl.php).

Please help

apaderno’s picture

Assigned: agbwatson » Unassigned

Notice that this issue has been posted in issue queue for a sandbox project without code. It's not an issue queue to ask support for, or post bugs in, Drupal core or third-party modules.

Despite the project name, this sandbox project is not linked to Drupal core in any way, and it may be removed at any time.