Reputation: 713
I'm trying to edit a page.tlp.php in the template folder, to modify the site's header url link depending on whether the user is logged in.
For example, if not logged in, display page 1, else display page 2. Code is kept simple to test the function.
<div id="site-name"<?php if ($hide_site_name) { print ' class="element-invisible"'; } ?>>
<strong>
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a>
<?php if (is_user_logged_in()) {echo "hi";} ?>
</strong>
</div>
At this point in time, the error.log indicates call to undefined function.
Am i meant to write this as a module, or is it possible to just have php in the template file, but i need to declare something, or i'm completely off track here?
Upvotes: 0
Views: 332
Reputation: 121
use the variable $logged_in, it is added by default in drupal
you aren't supposed to be calling functions in tpl files, instead use the preproccess_page hook to add all the variables you want.
function mytheme_preprocess_page(&$variables) {
$variables['is_awesome'] = ($GLOBALS['user']->name == 'MyName');
}
afterward the variable $is_awesome will be available in your page.tpl.php
Upvotes: 0
Reputation: 306
Function name is 'user_is_logged_in', not 'is_user_logged_in' (It is in wordpress) https://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_is_logged_in/7
Upvotes: 4