0

I have a node with a field which is a List (integer). I can print the value in node tpl with the following:

<?php print render($content['field_name']);  ?>

However I also need to style each result differently. For instance one of the options is 'large' and I want to add a background image to every 'large' result.

How can I do this? I was thinking if I could print the key value as a class along with the label the I could easily do the rest with CSS.

1 Answer 1

0

You should not actually want to do this in your node.tpl file. Drupal uses a system of (pre)processors to alter variables before they get rendered. That is where the logic should go.

Have a look at this topic that has a lot of explanation and references https://stackoverflow.com/questions/2383865/how-do-i-use-theme-preprocessor-functions-for-my-own-templates

Once you have your output ready you should be able to do the styling with CSS.

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.