Вы здесь

Друпал 7: search-result.tpl.php

search-result.tpl.php — шаблон формирующий отдельный результат поиска. Результаты отдаваемые этим шаблоном собираются в шаблоне search-results.tpl.php и вместе определяют разметку страницы с результатами поиска.

Переменные

  • $url — адрес результата
  • $title — заголовок результата
  • $snippet — сниппет (краткое описание) результата (не используется при поиске пользователей)
  • $info — мета-информация результата (не используется при поиске пользователей)
  • $info_split — то же самое, что $info, но информация разделена на массив ключей
  • $module: The machine-readable name of the module (tab) being searched, such as "node" or "user"
  • $title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template
  • $title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template

Ключи переменной $info_split

  • $info_split['type'] — тип документа
  • $info_split['user'] — автор документа (ссылка на профиль зависит от права просмотра профилей)
  • $info_split['date'] — последнее обновление документа (для даты и времени используется краткий формат)
  • $info_split['comment'] — количество комментариев, информация выводится в виде % комментариев, где % — счётчик (зависит от модуля Comment)
  • $info_split['upload'] — количество прикреплённых файлов, информация выводится в виде % файлов, где — % счётчик (зависит от модуля Upload)

Other variables:

  • $classes_array: Array of HTML class attribute values. It is flattened into a string within the variable $classes
  • $title_attributes_array: Array of HTML attributes for the title. It is flattened into a string within the variable $title_attributes
  • $content_attributes_array: Array of HTML attributes for the content. It is flattened into a string within the variable $content_attributes

Т.к. переменная $info снабжена ключами, то возможен прямой вывод пунктов. Этот массив не применяется при поиске пользователей, поэтому рекомендуется делать проверку. Стандартные ключи type, user и date всегда доступны при поиске документов. Модули могут предоставлять другие данные.

<?php
  php
if (isset($info_split['comment'])) : ?>

    <span class="info-comment">
      <?php print $info_split['comment']; ?>
    </span>
  <?php endif; ?>
?>

Для просмотра всех доступных данных переменной $info_split, можно использовать код:

<?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>

Пример шаблона

<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>
  </h3>
  <?php print render($title_suffix); ?>
  <div class="search-snippet-info">
    <?php if ($snippet) : ?>
      <p class="search-snippet"<?php print $content_attributes; ?>><?php print $snippet; ?></p>
    <?php endif; ?>
    <?php if ($info) : ?>
      <p class="search-info"><?php print $info; ?></p>
    <?php endif; ?>
  </div>
</li>