JenLampton on Drupal
Questions & Answers made better – by being made public.
Panel Pane visibility on cck field value
Posted by on June 12, 2010
I’m working in panels and have a node template. I want to add a visibility rule for a pane so that it is only visible when a CCK field is a particular value. The field is a single on/off checkbox, with key values “Yes” and “No”. I’m using PHP for the visibility rule, and tried this:
return ($node->field_listing_green[0]['value'] == ‘yes’);It produces an error on the page:
“Parse error: syntax error, unexpected ‘[' in .../ctools/plugins/access/php.inc(55) : eval()'d
code on line 1"
For starters the $node you are using in your visibility code doesn't
exist here, so if you want to run a test on part of it, you need to
load the node frist. (The node is already cached on this page so it's
not a big dea to call node_load() again). Do something like...
if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)){
$node = node_load(arg(1));
return ($node->field_listing_green[0]['value'] == ‘yes’);
}
I’m not sure why you got the PHP error, but what you are trying to do
is dependent on how you set up the cck field. I tried to guess how
yours was set up from your email, and added one to one of my content
types. I chose a “single on/off checkbox” where the “allowed values”
were defined as follows:
no|
yes|Yes
Then I created a node-view panel layout for this content type, and
added a pane with visibility settings as above, and it worked as
expected. I’m not sure what you were doing wrong, but perhaps this
recipe will help you?