Hi all,

As a total Drupal newbie I've been very impressed with this CMS. In no time I've been able to get my site up and running. There's been one question I haven't been able to get an answer to even after searching the docs and looking at the various modules.

I would like to be able to attach an image to a page and display the attached image in a block in the side bar when that page is viewed.

This seems like a simple tasks, but after looking at modules, views, panels, ckk and a bunch of other options I'm a bit overwhelmed. What's the easiest way to get this done?

Any pointers would be MUCH appreciated!

Thanks in advance.

Comments

gunner1095’s picture

I should also mention I'm using Drupal 6.

bartezz’s picture

Have a look at these modules;

http://drupal.org/project/imageapi
http://drupal.org/project/imagecache

http://drupal.org/project/cck
http://drupal.org/project/imagefield
http://drupal.org/project/cck_blocks

The imageapi will add image handling functionality to your Drupal site. Imagecache can be setup to automatically edit, scale, crop, etc your uploaded images.

With cck you can add fields to your content type (to your page content type for instance). imagefield is a cck add-on which will let you add, what's in a name, an imagefield cck field to your content type. And last but not least, with cck blocks you can output the images uploaded via that cck imagefield and edited with imagecache over imageapi to a region you set in your template.

Take it step by step :)

Cheers

________________
Live fast die young

gunner1095’s picture

Awesome, thanks! I missed the cck_block module. I think that will do the trick.

One other, hopefully quick question...

After adding a CCK image field I now have an image upload field in my page edit form. This is great, but what if I wanted to select an existing image on the server? Is there an image browser of some sort that would optionally replace the upload field?

(I hope I'm explaining this correctly.)

gunner1095’s picture

ok, almost got it going, except the image is being displayed as a link. I'm wondering how to display it as an image...

gunner1095’s picture

I got this figured out. It was a setting in the block configuration.

It's working perfectly now!

cgrdavies’s picture

I've also used this method and it seems to work fine. However, I want the image to appear in the block but not in the body of the node itself - is this possible?

escoles’s picture

You have two basic choices:

You can over-ride the node template for that node type (image node, let's say). There are at least two ways to do that: Create a new node.tpl.php file in your theme directory, or use Contemplate.

You can use CSS to simply hide the image. Look at the source and figure out what the outermost container is that you can hide without also hiding node content, and hide that. The CSS declaration would look something like this (your version might vary):

div.node.product-content div.image-attach-body,
div.node.donation-content div.image-attach-body
{
	display: none;
	visibility: hidden;
}

This version only hides the attached image in Product and Donation nodes. It should work with most themes, since I copied the default node template.

EDIT: I meant to add that CSS is definitely the simpler option.

bartezz’s picture

Simpler: yes, easier on the bandwidth: no... and pages take longer to download!
So if it's a larger image you are hiding with CSS I wouldn't recommend it but opt for the templating solution.

Cheers

________________
Live fast die young

cgrdavies’s picture

thanks so much for these solutions - I went down the CSS route and it worked perfectly.

Would I be right in saying that since, in this case, the image is being loaded in the block anyway then the bandwidth/loading times consideration isn't so pertinent?

escoles’s picture

In product pages, it's just a thumbnail, so I didn't worry about it there. Plus, Product nodes would have been time-consuming to theme. (Also, in our case, the full-sized image is almost always displayed in an image_attach block, so it would be just an http transaction, not a file transfer.)

If it's a case where the full-sized image is showing -- absolutely, get rid of it if you've got the time in your development cycle.

Actually themeing the functions on this seems like a bad idea, because if you theme away the link by re-theming the functions, you lose that ability everywhere. OTOH, I personally don't think that they images should be linked by default -- I've yet to find a case where I'd want to link the image.

gpk’s picture

Alternatively use image.module and the bundled image_attach.module which has the image block you are after. Inhibit display of the image in the actual node and Bob's your uncle.

gpk
----
www.alexoria.co.uk

gunner1095’s picture

Thank you! I will try this if I can't get CCK working...

escoles’s picture

.... which has the image block you are after.

I may be crazy, but I'm just not seeing a block for the image attached to the current node as a part of image_attach for D6. where does one find this block and how does one display it? I've looked on the Blocks page, I've checked the Permissions page* to see if there was a permission for using that block. I've looked at the "most recent image" and "random image" blocks -- neither of those does this.

EDIT:

The Attached Image block may not display after an initial install of image or image_attach.

For workaround:

http://drupal.org/node/269225#comment-880496

Issue:

http://drupal.org/node/426724#comment-1449046

--
*I've recently learned that some features are only accessible to user 1 if user 1 has been assigned to a role that has been assigned permission to use the feature.