The URL of my page view looks like my-view/%1/%2 The first argument %1 is term id of either vocabulary A or B or C and all of them are hierarchical taxonomy.

How can I conditionally display something in Views header global text area depending on which vocabulary %1 is or if it's parent term or child term?

5 Answers 5


I don't know if it's standard practice to answer such an old post, but another solution may be helpful to those who don't want to do any coding. You can conditionally attach a header by using Views Attachments. This may not be the best practice for a production site, but that's another discussion. This answer is just to let you know of the possibilities.

Add an Attachment display for each Vocabulary you want a separate header for, and set their properties according to the images below. Notice that all attachment properties are overridden, in order to not affect your main Page or Master (default) display.

Edit: The images displayed below are for Views 3.x. Hopefully, they are helpful for Views 2.x, as well.

Add Attachment: Add Attachment

Add an attachment for each header you want displayed conditionally (as shown above).

Attachment Filter:

Attachment Filter

The above filter will ensure no records are displayed by the attachment, only the header.

Contextual Filter (1/2):

Contextual Filter (1/2)

Set the contextual filter for each attachment (as shown above and below).

Contextual Filter (2/2):

Contextual Filter (2/2)

Set the term to be used for this attachment (my example is "Glossary"). Be sure Action to take if filter value does not validate is set to 'hide', so that only the desired header is displayed.

Attach To Page:

Attach To Page

Be sure to attach your attachment to something (here, attached to the "Page" display). Click on Global: Text Area to set your header.

Set Global: Text Area (in Attachment Header):

Set Header

Click Global: Text Area (prev image) and set your desired header. Notice: still overridden. Also be sure to check Display even if view has no result since the filter for the attachment excludes all records.

Page/default Contextual Filter:

Page/default Contextual Filter

Last, but not least, set the Contextual Filter for the main page itself (not an attachment) according to your needs.


I would suggest to use the panels module: there you can create a page that contains the view and add optional content based on available contexts.

  1. add an essentially blank global header text area to the view.
  2. use hook_views_pre_render() for the view to inspect the url arguments and insert the necessary content into the global header.
  3. profit.

You have done half of the thing. If there is too much code then, I guess the best option is to write a function inside a module, call the function in Global Text Area and pass the arguments.


I'd add the Views PHP module, the add the header as a PHP header.

From there I would user the argument from the URL for my conditional.

Ex: if your path is my-view/%1/%2 and your condition is based on %1 you'd do

if (arg(1) == 'foo'): print 'this'; else: print 'that'; endif;

if your path is my-view/%1/%2 and your condition is based on %2 you'd do

if (arg(2) == 'foo'): print 'this'; else: print 'that'; endif;

Your Answer

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