The entityreference field (field_parent) shows up in node.tpl using print render($content);, but isn't displayed in search-result.tpl. My search-result.tpl looks like this right now:

<li class="<?php print $classes; ?>"<?php print $attributes; ?>>

  <?php print render($title_prefix); ?>

  <h3 class="title"<?php print $title_attributes; ?>>
    <a href="<?php print $url; ?>"><?php print $title; ?></a>

  <?php print render($title_suffix); ?>

    <div class="submitted">
    <div class="imported-text">Imported on <?php print $info_split['date']; ?>.</div>

    <div class="hr"></div>

    <div class="content">
    <div class="comments-link"><a href="<?php print $url; ?>">Comments</a></div>
    <div class="other-content">

    <div class="field-name-field-download"><a href="<?php print $result['node']-> field_download[LANGUAGE_NONE][0]['url'] ?>">Download</a></div>
    <div class="field-name-field-lipsum"><span class="lipsum">Lipsum:</span> <?php print $result['node']-> field_lipsum[LANGUAGE_NONE][0]['value'] ?></div>



I tried using <?php print $result['node']-> field_parent[LANGUAGE_NONE][0]['value'] ?> but it gives me the error "Notice: Undefined index: value in include() (line 25 of ...\search-result.tpl.php)."

<?php print $result['node']-> field_parent[LANGUAGE_NONE][0]['entity'] ?> gives

Recoverable fatal error: Object of class stdClass could not be converted to string in include() (line 25 of ...\search-result.tpl.php).

<?php print $result['node']-> field_parent[LANGUAGE_NONE][0]['entityreference'] ?>

Notice: Undefined index: entityreference in include() (line 25 of ...\search-result.tpl.php).

  • have you tried using dpm($result) from the devel module? it would give you the array structure to more easily find the correct elements
    – Geoff
    May 8 '15 at 1:58
  • I've never used devel. Both documentation links I tried were dead, how can I use dpm($result) to solve this?
    – James
    May 8 '15 at 2:09
  • Just enable the devel module @Geoff linked to and then add <?php dpm($result); ?> to the top of search-result.tpl.php May 8 '15 at 3:50

I solved this by using teaser view as my search result. My search-result.tpl file now looks like:

<li class="<?php print $classes; ?>"<?php print $attributes; ?>>

<?php $v = node_view($result['node'], 'teaser'); print render($v); ?>


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.