0

Good morning, I use the Zen theme. I did override the node.tpl.php putting a copy in myzen / templates /, I saw that the content is printed with this statement:

print render ($ content);

my problem is that having made my own content type, content is an image and text, I would give a different width by css to my image and text. how do I make a reference with css at image and text placed separately?

2 Answers 2

1

The $content variable is an array (a 'render' array in Drupal parlance). You'll be able to render the parts of the content individually instead of all in one go if you want, and wrap them in specific HTML:

<div class="body">
  <?php echo render($content['body']); ?>
</div>

<div class="some-image-field">
  <?php echo render($content['field_some_image_field']); ?>
</div>

You can even provide a template file for just the content type you want to change, by calling it node--content-type-name.tpl.php, and just apply the changes to that particular content type.

For styling, each field will already be wrapped in HTML with many, many classes attached to it. Just fire up developer tools/firebug, inspect the elements, and you'll find the correct selectors to target with CSS. If that fails, you've can add the wrappers in yourself like in the code example above.

2
  • thanks! what is the best place to position the css as "body"?
    – Antilope
    Commented Jun 27, 2012 at 8:47
  • Sorry, not really sure what you mean could you elaborate a bit?
    – Clive
    Commented Jun 27, 2012 at 9:03
0

There are many ways you could this. You could use some of the preprocess functions in your themes template like THEME_preprocess_node() or maybe a bit deeper like THEME_preprocess_field().

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.