0

I have a single content type (webform) that I want to display in two or three different styles on my site. For instance, I may want to have some of the webform's CCK fields floated to the right on one webform page, and have them floated to the left on another. There will be many unique webform content items on the site, so individual CSS per-page styling would not work well, and I am looking for a point-and-click solution.

I was hoping that there would be a way for me to add a CCK field (or something similar) to the Webform content item that would allow me (or another admin user) to simply choose "style 1", "style 2", or "style 3" from a drop-down menu, and that style would be added to that Webform's page or div classes, allowing that form to be stylized according to one of three pre-created style sets.

Is this possible with an existing module? Any other ways in which I can go about accomplishing this?

Thanks!

2 Answers 2

1
// This code will add a class to the node based on a field in that node
function THEME_preprocess_node(&$vars) {
$node = $vars['node']; 
$output = '';

switch($node->type) {
  case 'advertisement':

  // Set class based on editor color selection; code duplicated for clarity.
  $field = field_get_items('node', $node, 'field_background_color');
  if($field) {
    $theme = field_view_value('node', $node, 'field_background_color', $field[0]);
    $term_name = $theme['#title'];
    $term_name = str_replace(' ', '-', $term_name);
    $css_name = strtolower($term_name);
    $vars['classes_array'][] = $css_name;
  }
  break;
  }
}
1
  • Thanks for your feedback, Greg. I actually found a nice and easy solution using Context. I'll post that solution below.
    – hockey2112
    Mar 26, 2013 at 20:50
0

I found a great way to accomplish this using the Context module.

http://drupal.org/node/1257822

First, I added a Taxonomy CCK field to the Webform content type, and then...

In Admin /Structure /Context, in a context, add a "Taxonomy" Condition of tag, "Theater," and set a "Theme HTML" Reaction.

This adds whatever class you specify to the body class for the webform page, depending on whether you select one of the qualifying taxonomy terms from the Taxonomy CCK field when editing that Webform.

Your Answer

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

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