Hia good themers,
I've been struggling for hours with something here, and could need a push!
I've recently jumped ship from the core profile module to Content Profile. I've set up a profile with a CCK Imagefield as the profile picture, and are now trying to theme my node.tpl.php and comment.tpl.php to use this Imagefield (which is set up with a default picture) there. Also, i use Imagecache to resize these.
First, in my content_profile-display-view.tpl.php
(the theme file for Content Profile) I've set up this:
print theme('imagecache', 'profilepic_profilepage', $node->field_profilepicture[0]['filepath'], $alt, $title, $attributes);
Which works just as expected. If the user has set a picture it shows in the right Imagecache preset, and if not the default image from Imagefield is displayed.
However, if I use this code in node.tpl.php:
// load the content profile object for the node author
$account_picture = content_profile_load('profile', $node->uid);
print theme('imagecache', 'profilepic_comments', $account_picture->field_profilepicture[0]['filepath'], $alt, $title, $attributes);
or similar in my comment.tpl.php, the default picture is *not* printed if the user has not set one, otherwise it works just fine.
Also, I've experimented with this:
if ($account_picture->field_profilepicture[0]['filepath']) {
print theme('imagecache', 'profilepic_comments', $account_picture->field_profilepicture[0]['filepath'], $alt, $title, $attributes);
} else {
print theme('imagecache', 'profilepic_comments', $default_picture, $alt, $title, $attributes);
}
;
Which also works if i hard code the path to the default picture where I have $default_picture above. However, I'd like to assign $default_picture to whatever the default picture for my specific Imagefield is, and I can find no way to do that :/
With the core profile module you could do this:
$default_picture = variable_get('user_picture_default', '');
..but I find no way to do a similar thing for the default value of an Imagefield..
so:
- Anyone knows why Imagefield prints the default image if nothing set in one template file, but not the two others, and / or
- Anyone knows how you can populate a variable for an Imagefield's default picture as described above, or
- Any other pointers?
:)
Comments
Same Question
Hi, did you figure out how to programatically fetch the default value for an imagefield?
No
Hia, sadly no, I still use an absolute reference to the default file in the file system..
Subscribing!!
Subscribing!!
---~~~***~~~---
aac
Subscribing, gonna take a
Subscribing, gonna take a look a little later, just bookmarking so I don't loose track of it. Good question btw.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
node_build_content()
node_load() by itself will not initialize default images for cck imagefields. I don't know about which template files load nodes in what way but here's what solved it for me:
If you do not want to build
If you do not want to build the whole node you can user
to get the default image
content_fields doesn't exist in D7
That should work for D6, but there is no content module for D7. Use the field_info_fields() for the same purpose. It'll return an array of all the available fields with their data.
Here is a way to get the uri for the default image of a FOOBAR field in D7.
Thank you!
I noticed that default image data is only loaded into the field data when the node IS the content. If the node is related or 'node_load'ed, the field is an empty array, which is unfortunate.
So in my node--BUNDLE.tpl.php I added this little snippet in an if/else to check for image data and to load the default if it's empty. a little bit hackish but works a treat! thanks!
field_info_fields is resource intensive
According to https://api.drupal.org/api/drupal/modules!field!field.info.inc/function/... Use of this function should be avoided when possible, since it loads and statically caches a potentially large array of information. Use field_info_field_map() instead.
Also, according to the above api document you may be better off using field_info_field.
http://blog.marceisaacson.com
D7 node_build_content() returns null
it operates on the node passed by reference, so better do:
node_build_content($node);
use other imagecache by term condition
I have 2 preset called
1. not-sold-image
2. sold-image
and taxonomy term
1. not sold
2. sold
How to set imagecache in my node.tpl.php if i wanto display image preset depend on taxonomy term?
so if taxonomy terms not sold were fulfilled imagecache not-sold-image will displayed, in otherword if if taxonomy terms sold were fulfilled imagecache sold-image will displayed ?
thank you for your assistance greatly appreciated
anjjriit - cipta-mobil.
Get Default Image path Drupal 7
1. Open template.php in your theme folder . If your theme dont have template.php, create it
2. Add
3 . Save template.php
Now you can call themename_default_field_image_path($field_name) in any tpl files
for eg:
Correct me if i am doin anything wrong :)
Use Drupal API
Hi Serjas,
I think what your code does is correct but it's better to use Drupal API which loads field configuration data from the database once and caches it statically instead of performing additional database queries to fetch again something what has been already fetched and is easily accessible via field_info_field().
This function can be reduced to something like this:
(I believe it works but haven't tested it)
BTW if you want to fetch a single record from a database query it's simpler to use fetchField method instead of a loop:
https://api.drupal.org/api/drupal/includes!database!database.inc/functio...