0

Is it possible to upload an image to Drupal which is accessible by all nodes programmatically?

What I want to do is upload an image to display as a banner (CSS background) for nodes that have a specific radio button selected.

My idea is to have the user upload the image to one place then in my template.php file detect which radio button has been selected & from that pull that image in as a CSS background.

Is this even possible?

1

Yes, any file uploaded into an image field in Drupal is accessible by its File API.

To address your issue, there are many ways to go about this. One solution that comes to mind is a multistep solution:

  1. Create a content type with an image field. You'll be using this content type to manage any background images you want.
  2. On the node type that you want to add an image background to, add an Entity Reference field that references the node type created in #1 with a Checkboxes/radio button widget.
  3. Edit your theme's template.php to add/update the MYTHEME_preprocess_node($variables) function. Inside of this function you'll be using $variables['node'], node_load(), file_load(), & drupal_add_css() to retrieve your selected image node reference, load the node, lookup the referenced file, & add inline CSS to your node display.
  • Thanks for the reply, certainly something I wouldn't have thought of. I'm going to give it ago this week & see if it solves my problem. – Neil Nand Jun 16 '15 at 2:07
  • Sorry it has taken me so long to accept this but it worked perfectly! – Neil Nand Aug 11 '15 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.