Hi,
i'm using image_attach in a content-type of mine.
I am also using the ContentTemplate (aka Contemplate) module to theme CCK teasers and body, but seems that if i edit the default ContentTemplate, the image i attached disappears (as does disappear any other non-CCK extra content! Already filed a feature request on Contemplate project page about this.)
So the question is:
Which php snippet shall one put in his template to output a picture uploaded with image_attach?
I tryed different ways, but didn't succeeded in this, could any good soul help please?
Comments
Comment #1
garg commentedHello. Were you able to find a solution for this? Thanks
Comment #2
david lesieur commentedTry this:
Comment #3
Patrick Nelson commentedThanks David - works a treat and it was just what I was looking for!
Thanks also kiteatlas for having already asked the question I was going to ask!
Comment #4
Patrick Nelson commentedActually, one question... how do you test to see if there is actually an image attached? The code displays the following error if there isn't actually an image attached:
Comment #5
david lesieur commentedGood question! Then try this:
Comment #6
Patrick Nelson commentedFantastic - works a treat. Thanks again, David.
Regards
Patrick
Comment #7
dodorama commentedwhat if I just want to output the img tag and not the themed image ?
Comment #8
dodorama commentedI had the answer by myself.
If you just want the img tag with link use:
If you just need to print the url to the image to tag it yourself use:
It works for me but take this with care, since my php skills are poor.
Comment #9
alexmay commentedThanks to all!
I have used code below, but it was only links to node, wich contain attached image.
I have modifyed your code, and now I get link to image page!!!
Comment #10
alexmay commentedI don't find the way, how attach more then 1 image to CCK-generated node, but I have enabled file (not image) attachment and I can now attach 1 main image (via image_upload module) and other images/files via file_attach.
Now, my final way to display 1 main image (thumbnail+link) and links (without previews :( ) to other images.
Here is:
Comment #11
Luneh commentedHi there,
I hope that you will be able to help a Drupal newbie struggling to get a nice site.
What I need to do with image_attach is to display the image separately from the other content of the node. I would like the image to be in another region defined in the template.
I tried to create a block with this code:
but nothing appeared on my page. When checking the page source, I can see that nothing that could be part of the block is mentioned either.
Anybody knows what I could do?
Many thanks in advance.
Caroline
Comment #12
Luneh commentedHi,
More about my problem.
I am totally newbie with php but it seems like ut does not find any image attached to my node (I can confirm there is one, it even appears above it at the moment).
When trying to use
in order to get rid of the "if" statement, I get this error:
Can somebody please help me find what to do?
Thanks.
Comment #13
Luneh commentedAgain, made some tests.
Here is something which works in a block:
It returns the image attached to the node we are on.
The problem is that I still get a SQL error on nodes which do not have any image attached. Which means that I need the "if" statement but I can't find how to build it.
if ($iid) { is not working as $iid is not defined. I guess that I need to define $iid before anything else but how to do it? I have found this in the image_attach.module code which could be a start but I do not exactly know how to use it:
Comment #14
david lesieur commentedTry this (untested):
Comment #15
Luneh commentedThanks, that did the trick ;)
Comment #16
drewish commentedthen mark it as fixed ;)
Comment #17
The.Clue commentedsnippets here work as a charme....but i still have a problem...
the point is that image_attach's content is shown by default AFTER the node content block. i added provvided snippet to node.tpl.php to print it BEFORE content block, and it works
but (obviously) the default one after the block is still showing and now i have two copies of the attached thumbnail in each node....
Comment #18
drewish commentedyou should update to the dev branch. the teaser is now put into the $node->content array so you can output everything in the order you'd like in your theme function now.
Comment #19
The.Clue commentedi _have_ the dev branch on...but attached img (in full node page view) is still at bottom, after the content body itself...
for now i fixed it with CSS (shrinking the content width and absolute positioning thumbnail at top of node container) but its not an elegant solution at all...
Comment #20
dmjossel commentedI've also got the dev branch on, and I cannot reposition the attached images using absolute positioning because teasers aren't all the same size.
Can the above poster be specific about where the attached image is in $content now and how to output it?
theme_image_attach_teaser used to output the teaser image with the node teaser itself appended. Now, it just outputs the teaser image. The node display function in the theme I'm using just outputs $content-- there's no call there to theme_image_attach_teaser. I assume some core module is doing that, and is passing $content with the teaser and teaser image in that order, and I can't see where to override it.
Comment #21
drewish commentedmarked http://drupal.org/node/129175 as a duplicate
Comment #22
drewish commentedi'm not sure i really like this approach but it should do what everyone wants. it adds two settings to the node type page so you can select the weight of the attached image for the teaser and body.
Comment #23
drewish commentedComment #24
dman commentedFWIW, I just rolled a similar (almost identical) solution before coming here to check the issues.
Mine is simpler (in a bad way) and doesn't allow for different settings for teaser vs bodies.
It works for me, so I'll post for reference.
(it's fun playing with the node content array nowadays)
Comment #25
drewish commentedmy patch allows you to configure the weight on a per-node-type basis, which would be useful when trying to set the order with multiple CCK nodes.
Comment #26
dman commentedYeah, I like yours. It adds a few things I hadn't considered.
Comment #27
drewish commentedmarked http://drupal.org/node/120267 as a duplicate of this
Comment #28
drewish commentedhere's a re-roll.
Comment #29
bloomaniac commentedwouldn't it be great to have a filter like http://drupal.org/project/image_filter to put the thumbnail where you want?
Comment #30
drewish commentedbloomaniac, feel free to use image_filter, nothing is stopping you. this patch is for a specific purpose.
Comment #31
dman commentedIf anybody wants a vote, I say +1 and roll with it. It's the way it should be, using weights like this.
Comment #32
drewish commentedthat last patch had a bug in it. i kind of thing if this much configuration info is going in, it would make sense to let the admin specify which size image is used in the teaser and body. i might take a swing at that before committing to this.
Comment #33
drewish commentedwhoops that had some test code in it. here's the right version.
Comment #34
drewish commentedhttp://drupal.org/node/135801 might be a duplicate of this
Comment #35
drewish commentedhere's a re-roll to keep it applying correctly. unless i get more feedback i'm probably just going to go a head and commit this.
Comment #36
dman commentedJust do it. It's the Right Thing(TM)
Comment #37
drewish commentedalright, it's committed.
Comment #38
(not verified) commented