0

I want to apply similar style to the nodes of same content type (style may vary or may be same between content types, but will definitely be same for the nodes of same content types) without creating a template file for each of the content type.

I know one way is to create a template file as node-TYPE.tpl.php but I am looking if there is some other way.

  • ah! you changed the tag from drupal 6 to drupal 7 but you missed editing node--TYPE.tpl.php to node-TYPE.tpl.php ,isn't? – arpitr Oct 4 '13 at 20:17
  • @arpitr I am a newbie and and not having much idea right now, that solution I found in the template suggestion so I wrote, anyways everyone learns from mistake only – user21493 Oct 5 '13 at 7:36
-2

If am not wrong than you want to add different class for each content type nodes (this is what the drupal already provides), but if you want to add class to body in your own way or may be adding same class to two different content types than you can try the following.

You can use hook_template_preprocess_node() for adding class to the contents following:

function MyTheme_preprocess_node(&$variables) {
  // If you want to same class to two different content types.
  if (('YOUR_CONTENT_TYPE' == $variables['type']) || ('ANOTHER_CONTENT_TYPE' == $variables['type'])) {
    $variables['classes_array'][] = 'CLASS-NAME';
  }
}
  • This is surprising to see how well this code does the same thing drupal already does.Are you sure you do not have content specific classes on <body> tag of nodes. – arpitr Oct 4 '13 at 19:19
  • @arpitr Yeah I was not having the unique classes but after adding the code it worked for me – user21493 Oct 4 '13 at 19:31
  • Wingryder, if by "apply similar style" you meant a common class per content type, I am afraid the above solution is redundant. Drupal node page itself comes with a class based on a content type. Say for a content type "video", it will have a class "node-video". Can you please explain how the above piece of code have helped you so that others can see if something is being missed. – Neo Oct 5 '13 at 2:30
  • @Neo This solution helped me in adding unique body class in my own may not necessarily the "node-video",& one more advantage of the above code is I can add even same class to two different content types – user21493 Oct 5 '13 at 7:49
  • @wingryder, good for you that it helped but I am afraid that was not what you were looking for, in future please try to phase your questions properly.only thing which kills me is the version of this question, – arpitr Oct 5 '13 at 8:35
1

You can use

Panels Module

It gives you UI to override node templates,providing appropriate selection criteria you can have different layout as per content types.

Display Suite

Display Suite allows you to take full control over how your content is displayed using a drag and drop interface. Arrange your nodes, views, comments, user data etc. the way you want without having to work your way through dozens of template files. A predefined list of layouts (D7 only) is available for even more drag and drop fun!

Your Answer

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