2

I set up a view in drupal 7 that displays all my content. I exposed filter criteria's Title and Taxonomy, so now there's a title and taxonomy search field that appears above the result set. How do I print custom text like "Search Results:" between the filters and the results?

2 Answers 2

4

This can easily be achieved using themeing.

  • In the edit view for your view click on advanced
  • At the bottom of the section is "theme information"
  • Look for the line "Display output" and from left to right the themeing becomes more specific
  • Decide how specific you want the themeing to be (hint if unsure go to the right)
  • Copy the theme file name (which should be something like views-view--example--page.tpl.php) and create a new file in your theme folder with that name
  • Click on the display options link and copy the contents of the file from the <?php through to the bottom of the fixed width text and paste that into the new file
  • Add your text after the code block that looks like this:

<?php if ($exposed): ?>

<div class="view-filters">

<?php print $exposed; ?>

</div>

<?php endif; ?>

  • Save the file
  • Click the "Back to theming information" link
  • Click the rescan template files link
  • Save your view
  • Visit the page your view is on
0

Quick edit to the previously provided response:

Copy the views-view.tpl.php provided by the Views module into your templates folder of your theme, and rename it views-view--example--page.tpl.php

After:

   <?php if ($exposed): ?>
 <div class="view-filters">
 <?php print $exposed; ?>
 </div>
<?php endif; ?>

add:

  <?php if (!$empty): ?>
    <?php print t('Your search results are below.'); ?>
  <?php endif; ?>

Save the file. Make sure to rescan you template files within the view.

This ensures that your custom text is only displayed when results are found. Without the check to see if the view is empty, your custom text will display even if no results are found, which is not good UX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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