I'm trying to get the authenticated user's image to show up in the header menu on my site, just like the new feature here on drupal.org.
I thought this would be simple with authcache, so... I added a block with this php and placed it in the header of my theme:
<div id="userpic">
<?php
if (user_is_logged_in()) {
global $user;
print theme('user_picture', array('account' => $user));
}
else {
print theme('image', array('path' => 'path/to/defaultimage.png', 'style_name' => 'thumbnail'));
}
?>
</div>
In the block's authcache settings, I enabled Ajax and per-user caching for 6 days.
I thought this would do the magic, but ended up seeing one user's image when another logs in - totally undesirable, of course.
I've been trying to understand how to solve this, and I believe the authcache_usercookie example module has some pointers. Unfortunately, I'm unable to crack those pointers since I'm not exactly an expert in module development.
I'd be very grateful if someone can help me with how to use authcache_usercookie to solve my problem. Anyone?
Comments
Comment #2
kandrupaler CreditAttribution: kandrupaler commentedThis is interesting. I was placing the block using the following code in my page.tpl.php:
Just to check, I removed this code and placed the block manually via the UI on admin/structure/block.
Now everything started working fine without doing anything special! What's going on here?
Is there a way to get it to work via page.tpl.php? I prefer it that way because I get fine-grain control on where to place it.
Comment #3
znerol CreditAttribution: znerol commentedInstead of rendering the block directly in the template, I recommend to add a custom region to your theme and just place the block into that region.
See also #2780485: Manually rendered blocks are not loaded via ajax
Comment #4
kandrupaler CreditAttribution: kandrupaler commentedThanks @znerol. Right now it's working within an existing region if I place it manually via the UI, so I'll leave it there. Thanks again for this great module and your superb support.
Comment #5
kandrupaler CreditAttribution: kandrupaler commented