Posted by ae@uberellis.com on November 19, 2008 at 10:58am
I need help with the logic to:
- Detect whether page.tpl.php is displaying a full node (one only, not listed)
- Detect if the author has uploaded a userpic, and if yes, display the userpic. If no, display the default userpic
Is it prudent to rather place this logic into template.php? Code a module? It would be awesome to have access to other features for the userpic, like having the option to either use gravatar url as opposed to uploading a picture. Not to mention anything imagecache as well as allowing the user to crop a square image from the uploaded picture.
As far as I can tell, the $picture variable is only available for node*.tpl.php and comment.tpl.php

Comments
UserPic
Have a look at the Avatar modules: (search downloads: "avatar")
I think it does what you need.
Avatar Approval
Avatar Selection <=
Unique Avatar
Avatar gallery
Avatar Blocks
Good Luck
ServeLime
www.ServeLime.com
Entrepreneurship is a journey to a fulfilled life - make it so.
Emile Botha
Entrepreneurship is a journey to a fulfilled life - make it so.
While we're at it
Also include posted by information from page.tpl.php
I need these in page.tpl specifically, to modify the page title (area). So.. if I could somehow not show the title in page.tpl, I could add all of the above logic into the node.tpl's
Here's how I currently display userpic from node.tpl
It's not the most elegant, I know... ImageCache for userpics puh-leeeeze!
<?php if ($submitted): ?>
<?php if ($node->picture != '') { ?>
<div class="picture"><img src="/<?php print $node->picture ?>" width="35px" height="35px" /></div><!-- $picture returns true -->
<?php } else { ?>
<div class="picture"><img src="/<?php print $directory ?>/images/user_default.png" alt="No picture uploaded" width="35px" height="35px" /></div>
<?php } ?>
<span class="submitted small"><?php print $submitted ?></span>
<?php endif; ?>
<?php if ($page == 0): ?>
<h3><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h3>
<?php endif; ?>
Maybe (in the
Maybe (in the node.tpl.php):
<?phpif ($node->nid == arg(1)) {
?>
and:
<?phpprint ($node->picture ? $node->picture : 'No picture');
?>
And/or, to change the page title:
<?phpdrupal_set_title('');
?>
Thanks for great tips Nightwatch and Vertice (offline)
I get acceptable results when doing the following in page.tpl
<?php if (theme_get_setting('toggle_node_info_'. $node->type)) { ?><div class="picture"><?php if ($node->picture) { print theme('image', $node->picture); } ?></div><?php } ?>Using the arg(1) (or 0 = 'node') was definitely a step in the right direction! It's downfall is always printing the author user pic regardless of theme settings.
Now to display 'Submitted by' info *koff*
<?php print theme('node_submitted', $node); ?>You should not rely on the
You should not rely on the path when working in node.tpl.php, but rather on
$page, a variable passen on to node.tpl.php that evaluates toTRUEif the node is being viewed as a page andFALSEif the node is being viewed in a list. If you rely onarg(0)/arg(1)node 33 listed in a view at the URL /node/33 would also show the avatar.