I would like to allow my users to choose a background image or color for a node. I created a content type with two fields: 'background image' of type image, and 'background color' of type color field.

I can retrieve the values of the fields on my module but how can I pass them to my stylesheet? Should I use the style attribute of my HTML elements?

The background color can be any color so I can't precreate css classes, or files.

Any idea on how to do this? Thank you!

1 Answer 1


I suggest you do it in your node.tpl.php. You can add the style attribute directly to the attributes array in a node preprocess.

in your template.php , load(add css file ) or insert in-line css style

function THEMENAME_preprocess_node(&$variables) {
  $type = $variables['type'];
   // dpm($$variables['node']);
  // as example
 $css = "p {background-color: $color }";
 drupal_add_css($css, 'inline');

you can do something like this .I hope this solution get you some good clue .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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