0

Including the following code:

<?php print 'This page was last modified on ' . date('j F Y', $node->changed);?>

in node.tpl.php displays the correct information on the site. However, I would like to display it in the footer instead at the end of the content so have moved it to page.tpl.php.

The problem with this is that on the homepage the following is being displayed:

This page was last modified on 1 January 1970

Which is clearly incorrect.

In addition, These error messages are displayed on every page:

Notice: Undefined variable: node in include() (line 201 of /home/mysite/public_html/sites/all/themes/mysite/templates/page.tpl.php).

Notice: Trying to get property of non-object in include() (line 201 of /home/mysite/public_html/sites/all/themes/mysite/templates/page.tpl.php).

How do I include the Page last updated text in the footer of every page?

  • Just check your server timezone – niksmac Feb 13 '13 at 6:52
2

You are trying to access the property of a loaded Node's object in the page template. This variable, $node, will only be available to the page template, typically page.tpl.php, only if the current path is loading a node.

In other words, if you are loading a path like node/NODE_ID, then you are guaranteed the variable will be available. Otherwise it won't be.

The error you are seeing is because of this reason. Try to navigate to a valid node URL and the error will be gone, the variable will be defined, and you can access it normally.

Provide a conditional check in your page template to make sure the variable exists before you access it.

Good Luck!

  • Thanks for that @9ee1 My front page is not a node, in the site settings the Default front page is set to "blank". What variable should I use on the homepage instead of $node? My front page is made up of menus and blocks... – kine456 Feb 13 '13 at 3:30
  • @kine456 Short and sweet answer is nothing out of the box :). Makes sense if you think about it too. Nodes are the building blocks of your content and thus, for all purposes, they are the pages that are being modified. If your front page is made up of only blocks and menus, what would the modification date represent in that context? If you really wanted to, you can probably write up a module that would calculate such a date based on your requirements and make it available to your template. I am not sure if there are any custom modules that you can use. – 9ee1 Feb 13 '13 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.