This will be my last issue for today, promise:
I am using with success the Imagecache.module to generate on-the-fly thumbnails when they are needed on the page the visitor is actually browsing. This is a really nice module that well integrates with CCK and Imagefield.
To display a thumbnail, the module creates a "rule directory" that when called by the theme, generates automatically the resized image. The code needed is the following:
in Contemplate.module generated templates:
<?php foreach ((array)$field_image as $item) { ?>
<div class="field-item"> <?php print '<img src="/files/imagecache/rulename/'.$item['filepath']. '">'; ?> </div>
<?php } ?>
in node-content-type.tpl.php files (slightly different):
<?php foreach ((array)$field_image as $item) { ?>
<div class="field-item"> <?php print '<img src="/files/imagecache/rulename/'.$node->$item[0]['filepath']. '">'; ?> </div>
<?php } ?>
NOW:
i tryed many possible combinations ($node, $view, [0],...) of the above code in my views-list-viewname.tpl.php files generated with views_theming_wizard (also this amazing piece of code!), but i cannot succeed in displaying thumbnails...
Anyone who knows where to put his hands could share the right code to make this work?
Thank you very much in advance
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | imagefield.module_4.patch | 2.97 KB | karens |
| #26 | imagefield.module_3.patch | 2.94 KB | karens |
| #23 | HOWTO - Imagefield and List Views.rtf.txt | 2.94 KB | marcoBauli |
Comments
Comment #1
dopry commentedI need to integrate better integration with views for imagecache... View provides the necessary callbacks for me to hook into it. The issue is centered in imagecache.
.darrel.
Comment #2
marcoBauli commentedoh, you caught my help request on Views project page so Dopry..! ;P
Can i ask what is the priority about this for you? This is kind of urgent for me, and i am willing to pay a bounty (and offering testing as well ;) to see this kind of integration.
I ask directly to you that are the creator of the module first if you might be accepting this..?
Thanks in advance
Comment #3
dopry commentedit is a fairly high priority for me, but my development bandwidth is occupied by a couple clients whose sites I'm working on and trying to get filesystem.module stabilized for inclusion before the code freeze. CCK and imagecache are still projects I see as being out towards the horizon... filesystem.module and an improved file api are more immediate concerns for me. However go ahead an offer a bounty. I will be happy to commit patches to imagecache or add commit permissions to interested developers...
My future hopes are to extend the ui for better integration for theming. Much of the work of this module is too specific though to put outside of a theme developers hands.
I'd also like to use actions.module to provide the filters. making it easier to implement and share filters.
.darrel.
Comment #4
marcoBauli commentedwell, some good intentions to learn (and some help from the community!) are enough to make this a powerfull tool also for an ex photoshop/illustrator guy like me ;)
Unfortunately my time schedule has never been so strict: my site makes extensive use of Views+CCK+Imagecache, and is therefore unusable at the moment without this integration (huge images breaking layout almost everywhere!).
So this is my offer:
willing to pay up to US$150, plus testing and pouring any usefull code snippet into the readme.txt if this can be done let's say by the end of the week.
Sounds attractive/feasable to you Dopry, or to anyone who knows enough and can meet this deadline? (You can contact me also from my contact form).
thank you!
Comment #5
introfini commentedI think I've done want you want. This http://onossocasamento.pt/fornecedores_aprovados_teaser was accomplish with theming PHPtemplate, views, imagecache, imagefield and cck.
It's a views teaser list.
Comment #6
marcoBauli commentedIntrofini, looks like we are using different approaches:
...how did you manage to call a .tpl file from views, and what kind of view did you use (list, full node, teaser,..)?
I guess you themed your node with node-[content-type].tpl.php, and then used a *teaser* or *full node* view to show it, am i right?
display those imagecache thumbnails in a *list view* themed with a phptemplate file like views-list-[yourviewname].tpl.php (file created manually, or automatically generated by the views_theming_wizard.module).
the more i think about this, the more i am convinced it is a problem specific with *list views*...
Comment #7
dopry commentedok so I wrapped the return to the views_item_handler in
return theme('imagefield_view_image', $file, $node_field_item['alt'], $node_field_item['title']);
so you should be able to override the value being returned to the view in imagefield v1.9.
I've got a few more ui changes an I will branch for 4.7.
Comment #8
introfini commented@kiteatlas
I’m calling the views in my page this way:
Comment #9
marcoBauli commentedDopry, thank you for the quick support man, so does this mean is now possible to trigger imagecache also from a views-list-[yourviewname].tpl.php *list view* template?
If yes (or when this will be ready) could you please grace me with the right code to copy in that file to output resized imagecache images from it?
Note:
ty
Comment #10
dopry commentedyou're gonna have to override that theme function to get the path value into the theme...
Comment #11
marcoBauli commented@introfini: good to know that this works for *Teaser List* views. Unfortunately i am trying to make this happen with *List View* views... thx by the way!
@dopry: just came back from Handbook pages about "Overriding theme functions", but this seems a too big bite for me considering my complete php-n00bnes... this was the reason of my offer at #4 above.
i will put that announce on the forum (much proper place than here also!) hoping there is some available developer not yet on holyday, willing to help and gain some quick buck..
thank you for the help up to here guys!
Comment #12
dopry commentedin your template.php try something like...
function phptemplate_imagefield_view_image($file, $alt, $title) {
return $file['path'];
}
Comment #13
marcoBauli commentedok, i am improvising now:
the following is the theming function for my *List View* as it is outputted by the Views_theming_wizard:
If i simply paste the 3 lines function you gave me at #12 above nothing happens (that would be too easy, of course ;).
I had a look at the
imagefield_field_view_itemfunction in imagefield.module and tryed integrating it in myphptemplate_views_view_list_featured_itemfunction, changing the first 4 lines into:At least i managed to get a Warning:
Missing argument 4,5,6,7 for phptemplate_views_view_list_featured_item() in /home/public_html/drupal/sites/mysite.com/themes/mytheme/template.php on line 108.
..honestly don't know where to head now, except from the closest library and buy a php guide...!
Comment #14
dopry commentedyeah those variables in the function declaration aren't being passed to the theme function... You're pretty much on your own if you can't navigate the current php waters you're in. google and php.net are often better than the library,
Comment #15
marcoBauli commentedFinal note:
i can confirm that this problem exists only with "List Views".
"Teaser List" and "Full node list" work as expected togheter with imagefield+imagecache.
I think i will turn back to "Teaser Lists" untill this get's fixed.
cheers
Comment #16
dopry commentedare you talking aboun imagecache or imagefield... I know list views works for imagefield... the themed image tag is returned as the field value in the list view... did you add the imagefield to the fields in the view?
Comment #17
marcoBauli commentedhi dopry, yes i added imagefield to the fields in the view, but i couldn't manage to use imagecache (using views_theme_wizard + views-list-[viewname].tpl.php file) to output thumbnails instead of original images out of them.
This really seems a problem with the imagecache module when used togheter with list views. You can try yourself trying to display a resized image in a *list view* containing an imagefield as field.
I asked a developer to fix this, the solution he found is the following:
1. paste into the imagecache.module the following function:
2. add
$vars['img_path'] = _imagefield_file_path($node->node_data_field_main_image_field_main_image_fid);afterin the code automatically generated by the views_theme_wizard.
3. add
<? if ($img_path!='') print '<img src="/files/imagecache/[yourrulename]/'.$img_path. '">'; ?>in your views-list-[yourviewname].tpl.php file to call the ruleset.Oh, of course any review of the patch greatly apreciated ;)
Comment #18
marcoBauli commentedComment #19
marcoBauli commentedOops
in step number 1 above:
'function theme_imagefield_image_preview' is already part of the module, so please do NOT paste the last 4 lines!
Comment #20
dopry commentedkiteatlas, can you test the latest version of imagecache... I made it a little easier to use I hope...
you can use theme('imagecache', $namespace, $image_path) to create the image tags now.
if you're using views imagecache won't work since imagefield returns a themed image tag from the
_view_item hook. You'd be best to use the raw data from node->fieldname if it is available in your view.
I've also modified imagecache so it should work with a non-default files path.
Comment #21
marcoBauli commentedohhh, sorry guys, this is my first patch and i did it the day i was back from vacations....
on #17, point 1: the function needs to be pasted into the imagefield.module, not into imagecache.
@dopry: with the patch above (sorry, a bit messy, if interested in a neat version just contact me) imagecache DO work with views. What you mean by: "use the raw data from node->fieldname if it is available in your view."? :o
will test new imagecache soon
Comment #22
dopry commentedplease submit your patch as a unified diff an not inline.
Comment #23
marcoBauli commentedi'm sorry, i actually don't know how to make a patch (diff).
Still the code DOES work and solves the problem: there is only to add few lines of code to pass the right variables in the template files.
Those interested can find a revised HOWTO attached here, which explains how to make Imagecache and 'List' Views work togheter.
Hope it can help anyhow
Comment #24
dopry commentedplease learn.
patch is http://drupal.org/diffandpatch
It will make it much easier to present you ideas and make you changes much easier to see.
Comment #25
dopry commentedmoving this to imagefield... kiteatlas, have you had a chance to roll a patch yet?
Comment #26
karens commentedThe imagefield module needed to be updated with the new formatter fields added by the content module. As I was adding them in, I saw a way to use them to make all imagecache rulesets available as additional formatters, eliminating the need for the previous patch or any adjustment in the theme.
Here's what this patch does:
1) It adds in the formatters and sets up the 'default' formatter to display the full size view of the image.
2) It checks to see if imagecache is enabled. If so, it adds to the formatters array with an option for each ruleset that has been defined.
3) It alters the theme in imagefield to append the imagecache path if a format other than 'default' is chosen.
4) In views, the field is has a drop down list of available formats to choose from for displaying the image in table or list views (teaser and full node views use the default full image).
It should be possible to use the formatter to alter the teaser view, too, but I didn't take it that far. You can use the formatters in tpl files, too. Use something like content_format($field, $item, 'default'), changing 'default' to the ruleset you want to use for the display.
There is probably still some adjustment needed and I've just done some preliminary testing, but it seems to basically be working.
Comment #27
karens commentedAccording to the cck documentation, you should be able to use content_views($field, $item, $format) to display a field, but that doesn't seem to work. However the following does work in a tpl file after this patch is applied (assuming you have created a rule in imagecache called 'thumb':
That code will display the full size image on pages and the thumbnail on teasers.
Comment #28
karens commentedOne more time on the patch. I just realized there is a theme for imagecache images and it fixed some erratic problems with paths on my multi-site installation, so I switched things around to use that if an imagecache rule was selected. This also makes the patch simpler and easier to understand.
Comment #29
marcoBauli commentedoohhh..these Views + Imagecache + Imagefield issues and relative patches (mine as well!) are making my head spin!! <:|
@karenS: I applied your patch, but cannot confirm.. No extra options appear in Views under "Image:" in Fields section. Also, do i need to add those three lines of code into the view-list.tpl.php in order to make Imagefield (Imagecache) work with List Views?
@dopry: Tryed to make a proper patch for my coder's solution above (i read the explanation on that node dopry, but i'm no geek nor i know unix commands..) , but unfortunately some little pieces of code need to be added in 3 files (imagefield.module, template.php and views-list-myview.tpl.php), and i didn't manage to get out of it...
@any volunterous developer: that solution DOES work, it only needs to be understood a bit and properly integrated into the module....maybe Karens solution is even easier...no experience enough to tell this..
Comment #30
karens commentedBe sure to clear your cache -- both cck and views are doing lots of caching. Once you apply my patch if you add an imagefield to a view you will see a drop down list of available formats to select from. The patch adds the formatters to imagefield, and that needs to be done anyway, so it's not really a preference of one method over another, it's just a question of whether or not adding options from imagecache to the formatters list will work. If not, it will have to be done by themeing as you have done, but it *should* work if imagecache is installed.
Comment #31
karens commentedAlso, the three lines of code are what you need to get this to work outside of views (like in your full node or teaser). You should not need to do anything in your tpl file to get the right display in views.
Comment #32
marcoBauli commented@karenS: thanks for clearing those things! i manually applied your patch to imagefield module v.1.9 (removed the lines of my patch of course ;) ), but got the following error:
Fatal error: Call to undefined function: _imagecache_get_presets() in /home/kiteatla/public_html/drupal/modules/imagefield/imagefield.module on line 489
maybe i should apply it to another more recent version (1.10) of the module?
Comment #33
karens commentedLooks like that function is only available in the cvs version of imagecache, so you need that version. I didn't realize there were differences, so this approach may not work in the 4.7 version.
Comment #34
karens commentedAlso, the patch is for the cvs version of imagefield, so be sure you are using that.
Comment #35
dopry commentedI'm going to get this commited this after noon and patch up the 4.7 branch to match HEAD.
Comment #36
brst t commentedJust to echo kiteatlas, I received pretty much the same error in 4.7, applying it to versions 1.9.2.1 and 1.10. Both patch_3 and _4 on 1.10 and clearing the cache at every change.
Fatal error: Call to undefined function: _imagecache_get_presets() in /modules/imagefield/imagefield.module on line 475Comment #37
brst t commenteder - 4.7.3 - to be exact
Comment #38
whereisian commentedI went to CVS and installed 1.10 of imagefield. I also installed CVS version 1.15 of imagecache . I installed patch from #28. Image field now had my imagecache profiles available. My table view now displays quite nicely. No errors or hiccups so far.
The issue is now that mulitple images in the same field cause multiple listing in views. In my teaser template, I simply removed the foreach condition generated by contemplate. It seems messy, but it works (seems to display last image uploaded). I'm assuming that I can do something like that again. Well, that's my next task.
Handling multiple images is the only thing missing that I can see. Excellent work.
Comment #39
karens commented@trish t - As noted above, this only works in the cvs version of imagefield and imagecache. Dopry indicated in #35 that he plans to update 4.7 to match head and when that is done it should work in 4.7 also.
@whereisian - Glad to hear it worked for you. The problems with multiple value fields is a known views/cck issue that is true for all cck fields that have multiple values. Fixing that is outside the scope of this patch.
Comment #40
marcoBauli commentedyay, works here too! Really like the possibility to choose in the options the desired ruleset, sweet :)
Only a question: you think it will work also with a View themed with the VIews_theme_wizard? Doubting because in the code it automatically generates (
print $field_main_image_fid) i cannot see any kind of reference to the Imagecache ruleset...?
Thank you
Comment #41
dopry commentedKarenS's patch from #28 commited to HEAD and DRUPAL-4-7 branches.
Comment #42
karens commented@dopry, the patch uses the _imagecache_get_presets() function, so it won't work in imagecache 4.7 unless it is updated to include that function. My read from the comments below was that you planned to do so, just wanted to make sure you realized that since I don't see an update to imagecache :-)
Setting back to active just to be sure you see this message...
Comment #43
dopry commentedimagecache_get_presets has been in imagecache 4.7 for two weeks now.
Comment #44
karens commentedSorry! Missed that.
Comment #45
kriskhaira commented#38 (by whereisian) worked for me :)
Comment #46
marcoBauli commentedjust a note: this patch is not compatible with the "Specify default /images folder patch" (a Parse error is thrown against the last line of imagefield.module file if both patches applied)
other than that works sweet togheter with Views, thanks again!
Comment #47
(not verified) commentedComment #48
gemini commentedIt looks like in the Views variable $field_image_id (when using imagecache) outputs default file system directory twice like the following:
Comment #49
yched commentedNo, this is the actual address where imagecache has your processed image available
Comment #50
gemini commentedhow come it wasn't doing that before? And I'm not sure what I've done, but I is showing them without the redundant file folder for me again.. I may have adjusted paths in the templates... I'm not sure I do so many changed that I don't remember things anymore...
Comment #51
dman commentedAre you aware how OLD this issue that you've tacked on to is?
Anyway, what you are seeing is how imagecache will accept either full (site-relative) paths as input, or, if the path given is not full, it'll look for the same path within the configured /files directory.
If you request [filesedir]/imagecache/[rulename]/image.jpg
The result will be drawn from
[sitefolder]/image.jpg
or
[sitefolder]/[filesdir]/image.jpg
Whichever exists.
Thus requests to
and
http://xxx.xxx/files/imagecache/image_rule/imagefolder/image.jpg
are both valid, and will resolve to the same result.
Yep, it's a bit messy, but the flexibility is useful sometimes. If the source path you've been handed already contains the files/ prefix then you need that extra behaviour, or you'd have to trim it off again before letting imagecache glue it back (!). Choose your preferred version.
Anyway. wrong issue thread I think
Comment #52
gemini commentedThanks for the explanation. I guess I saw it as an issue just because I had both cases on the same site... and what was the most weired about it, - images in the same view had different paths as you showed... I couldn't understand how images in the same content type in one view would have different path cases... that's the reason I came here.
Comment #53
(not verified) commented