0

I have an Article content type that has related_news field. It displays inside the article text as a box.

In node--article.tpl.php I have the following code:

<?php
  // We hide the comments and links now so that we can render them later.
     hide($content['comments']);
     hide($content['links']);
     hide($content['field_addthis']);    
     print render($content);
?>

I found that I can hide the related_news field using hide as:

hide($content['field_related_news']);

Is there any function like hide that could able to wrap the that field in custom HTML like <div class="custom">...</div>?

I tried the following:

//$content['field_related_news'] = "***". $content['field_related_news']."***";

But it causes to hide the field from the node.

2

You could easily achieve that in your node file by using the field_view_field() function and hiding it from the default render($content).

To do that just set the display options in your custom content type to hide the title or whatever you want and put the following php code in your template:

<?php $related = field_view_field('node', $node, 'field_related_news'); ?>
<div class="custom"><?php print render($related); ?></div>

Don't forget that you will need to hide your field in the render($content) otherwise you will see it twice.

|improve this answer|||||
3

You can achieve this by creating field tpl file.

Refer field.tpl.php

Create tpl file named as field--field_related_news.tpl.php

|improve this answer|||||

Your Answer

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

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