0

I'm stuck with this problem. In the following code, I want to replace the "field_portfolio_categories" by the "body field" in a custom tpl file.

<div class="portfolio-description">
    <h3 class="name"><?php print $title; ?></h3>
    <?php print render($content['field_portfolio_categories']); ?>
</div>        

So I change it to:

   <div class="portfolio-description">
        <h3 class="name"><?php print $title; ?></h3>
        <div><?php print $body; ?></div>
    </div>   

In the node, instead of body content, I see "Array"
And this is the error message:

Notice : Array to string conversion in include() (ligne 41...

Any idea what's wrong?

Here is the complete template code:

    <?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
hide($content['body']);
//$original_image = file_create_url($node->field_portfolio_images['und'][0]['uri']);
$lightboxrel = 'portfolio_' . $nid;
$portfolio_images = field_get_items('node', $node, 'field_image');
$first_image = '';
if ($portfolio_images) {
  foreach ($portfolio_images as $k => $portfolio_image) {
    if ($k == 0) {
      $first_image = file_create_url($portfolio_image['uri']);
    } else {
      $image_path = file_create_url($portfolio_image['uri']);
      print '<a href="' . $image_path . '" rel="prettyPhoto[' . $lightboxrel . ']" style="display:none">&nbsp;</a>';
    }
  }
}
?>
<div id="node-<?php print $node->nid; ?>" class="portfolio-text <?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<?php print render($title_prefix); ?>
<?php print render($title_suffix); ?>
<div class="ImageWrapper content"<?php print $content_attributes; ?>>
    <div class="portfolio-images">
        <?php print render($content['field_image']); ?>
    </div>
    <div class="ImageOverlayLi"></div>
    <div class="portfolio-overlay">            
        <div class="portfolio-inner">
            <div class="portfolio-info">
                <div class="portfolio-tools">
                   <a href="<?php print $first_image;?>" rel="prettyPhoto[<?php print $lightboxrel;?>]" data-toggle="tooltip" data-original-title="<?php print t('View Image');?>" data-placement="bottom" class="zoom dtooltip"><span class="fa fa-expand"></span></a>
                </div>              
            </div>
        </div>
    </div>
</div>
<div class="portfolio-description">
    <h3 class="name"><?php print $title; ?></h3>
    <?php print_r($content['body']); ?>
    <?php //print render($content['body']); ?>
</div>        
<?php //print render($content['links']); ?>
<?php //print render($content['comments']); ?>

3

Your code should be:

    <?php
// We hide the comments and links now so that we can render them later.
hide($content['comments']);
hide($content['links']);
//$original_image = file_create_url($node->field_portfolio_images['und'][0]['uri']);
$lightboxrel = 'portfolio_' . $nid;
$portfolio_images = field_get_items('node', $node, 'field_image');
$first_image = '';
if ($portfolio_images) {
  foreach ($portfolio_images as $k => $portfolio_image) {
    if ($k == 0) {
      $first_image = file_create_url($portfolio_image['uri']);
    } else {
      $image_path = file_create_url($portfolio_image['uri']);
      print '<a href="' . $image_path . '" rel="prettyPhoto[' . $lightboxrel . ']" style="display:none">&nbsp;</a>';
    }
  }
}
?>
<div id="node-<?php print $node->nid; ?>" class="portfolio-text <?php print $classes; ?> clearfix"<?php print $attributes; ?>>
<?php print render($title_prefix); ?>
<?php print render($title_suffix); ?>
<div class="ImageWrapper content"<?php print $content_attributes; ?>>
    <div class="portfolio-images">
        <?php print render($content['field_image']); ?>
    </div>
    <div class="ImageOverlayLi"></div>
    <div class="portfolio-overlay">            
        <div class="portfolio-inner">
            <div class="portfolio-info">
                <div class="portfolio-tools">
                   <a href="<?php print $first_image;?>" rel="prettyPhoto[<?php print $lightboxrel;?>]" data-toggle="tooltip" data-original-title="<?php print t('View Image');?>" data-placement="bottom" class="zoom dtooltip"><span class="fa fa-expand"></span></a>
                </div>              
            </div>
        </div>
    </div>
</div>
<div class="portfolio-description">
    <h3 class="name"><?php print $title; ?></h3>
    <?php print render($content['body']); ?>
</div>        
<?php //print render($content['links']); ?>
<?php //print render($content['comments']); ?>
| improve this answer | |
  • Thanks Adrian, That what i did first. The error is gone but the text is not showing. Any idea why? There is this line at the beginning: hide($content['body']); I tried to put it in comment but doesn't work either. – P.Roy Dec 9 '15 at 18:30
  • @P.Roy can you edit your question with the whole template file? and with the output of dpm($content['body']) or print_r($content['body']) – Adrian Cid Almaguer Dec 9 '15 at 19:11
  • I tried print_r($content['body']) but it gives me: Array ( [#printed] => 1 ) instead of text. I pasted the entire code in the question. Thanks – P.Roy Dec 9 '15 at 19:27
  • @P.Roy and you have text in the body of the node? – Adrian Cid Almaguer Dec 9 '15 at 19:31
  • Yes, there's text in the body – P.Roy Dec 9 '15 at 19:52
-1

The "problem" comes from manage display. Besides the default tab, there are 3 other tabs where I can click to show/hide fields. In order to see the body text, I had to click on Teaser text and show the body tag.

| 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.