Recipe 18: Empty Text, with PHP
Note
Ingredients
Completed region_term view (Recipe 17)
What shall we do when the website includes generated links to taxonomy terms, but some of the terms are not yet applied? Rather than showing visitors a blank view if they click on an unused term, we will provide a more informative message. Views UI offers an Empty Text option into which you can place a text-only message, HTML, or PHP. In this recipe, we'll use a snippet of PHP with HTML. We will then create a taxonomy list to demonstrate the variable text.
Open the view you created in Recipe 17 (if you have not completed that recipe, you can still follow this recipe with any taxonomy view).
Open the Empty Text fieldset found inside the Page fieldset. PHP is certainly not required in the Empty Text. You could fill it with simple text, such as:
Sorry, there is no content tagged yet for this region
For our purposes, we will add the PHP snippet as follows:
<?php $view = $GLOBALS['current_view']; $args = $view...