In Protecting content from non-logged in users when using phptemplate overrides there is talk about how to customize the template.php so that anonymous users cannot see private information on the site, since overiding via phptemplate goes around permissions.
I'd like to extend this to allow more customization in two ways
- display different page layouts for anonymous and logged in users (eg- display left and right columns only for logged in users).
- create different page layouts depending on what is on the page (eg- blog)
To approach task #1 i've tried this in my template.php:
/**
* check if the user is logged in before invoking the template override
*/
global $user;
if($user->uid) { // check to see if the user is logged in
function phptemplate_page($content, $title = NULL, $breadcrumb = NULL) {
return _phptemplate_callback('page', $vars);
}
}
elseif (! $user->uid) {
function phptemplate_page($content, $title = NULL, $breadcrumb = NULL) {
return _phptemplate_callback('page_anon', $vars);
}
}
This, in theory, would call page_anon.tpl.php for anonymous users and page.tpl.php for registered users. But I get this error:
Fatal error: Cannot redeclare phptemplate_page() (previously declared in *edit*/themes/engines/phptemplate/phptemplate.engine:143) in *edit*/themes/my_theme/template.php on line 15
The line # is actually corresponding to the first mention of phptemplate_page, i've edited out the parts that you can see by following the link above.
So am I to assume that it's not possible to customize the call to page.tpl.php? Or am I missing something else?
I think the problem will also help solve task #2.