Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I use the following code to pull up a referenced entity in my product template.
<?php if (!empty($node->field_related_product['und'])): ?>
<p class="related-product"> <strong>Related Products:</strong>
<ul>
<?php
foreach ($node->field_related_product['und'] as $related) {
?>
<li> <a href="/node/<?php print $related['target_id']; ?>">Item # <?php print $related['entity']->title; ?></a></li>
<?php
}
?>
</ul>
</p>
<?php endif; ?>
It keeps on giving me the following error:
- Notice: Undefined index: entity in include() (line 89 of node--products.tpl.php).
- Notice: Trying to get property of non-object in include() (line 89 of node--products.tpl.php).
Line 89 is:
<li> <a href="/node/<?php print $related['target_id']; ?>">Item # <?php print $related['entity']->title; ?></a></li>
Any suggestions?
Note: The actual referenced information displays just fine.
Comments
Comment #1
FranCarstens CreditAttribution: FranCarstens commentedTickle.
Comment #1.0
FranCarstens CreditAttribution: FranCarstens commentedAdded note.