Community Documentation

Panels 3: Pane Visibility Rules (Evaluating $contexts Variable)

Last updated October 24, 2011. Created by steveoliver on October 24, 2011.
Log in to edit this page.

Panel panes can be configured to appear when PHP code evaluates TRUE.

For example, a pane displaying the field(s) for a node may only make sense when that field actually has values.

Using the $contexts variable available to content pane visibility settings, one can evaluate such a condition in PHP.

  1. Add a new rule
    Add new visibility rule to panel pane.Select PHP Code option when configuring new panel pane visibility rule.

  2. Inspect the $contexts variable

    While the PHP code must ultimately return a boolean value, temporarily output the contents of our $contexts variable using drupal_set_message():

    Temporarily output contexts variable as Drupal message.

    Visit your Panels page and you will see the output of the entire $contexts variable -- a variety of nested objects and arrays pertaining to the page.

  3. Evaluate your condition(s)

    After finding the $contexts properties or element(s), return a boolean value (optionally using the negation (NOT) option instead of a PHP operator):

    PHP code returns a boolean value to Panels visibility rule check

In this example, the panel pane will only appear when the specified condition is met--when the array defining the node's file_field property (array) is not empty.

Comments

I've spent the whole day

I've spent the whole day trying to solve my problem, and the answer was here. Thank you for this.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Audience
Designers/themers, Programmers, Site administrators
Level
Intermediate
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here