Created
June 14, 2011 19:33
-
-
Save gavinblair/1025666 to your computer and use it in GitHub Desktop.
Drupal - Get access to the $node variable in page.tpl.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//we want the node, outside of node.tpl.php! | |
$node = $variables['node']; |
Using $variables['node'] in page.tpl.php is evil? Is it evil as in it causes more queries and load time, or evil as in non-MVC?
Drupal is quite non-mvc by itself (a lot of the view stuff is handled in the controller layer imo) so I don't think it is that...
I just mean, is it bad for performance, or is it bad in the way that putting functional code (setting a variable) is bad in a template file?
More maintainable maybe? Templates are meant to be changed... template.php is more constant?
You should probably also do this:
$node = &$variables['node'];
so that changes to the node are actual changes to the node.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure to do this in your template.php though (inside a hook_preprocess_page()) Don't be evil and do it directly in the page.tpl.php template :)