Using a CCK Field in PHP Selection Rule

Events happening in the community are now at Drupal community events on www.drupal.org.
Lloyd's picture

I've tried to use the code below to display a specific Panels Variant based upon a CCK field value on a text > select list field. So far it's not working. Do I need to add anything to Panels contexts to get something like this to work? Any other explanation?

$return = FALSE;
if( isset($contexts['argument_nid_1']->data->field_landing_page_type[0]['value']) ){
  if( $contexts['argument_nid_1']->data->field_landing_page_type[0]['value'] == 'Info Both' ){
    $return = TRUE;
  }
}
return $return;

Additionally, the Available values list for the CCK select list field include:

Webinar Both | Webinar registration form with More Info and Join Webinar buttons
Info Both | More Info form with More Info and Watch Webinar buttons

Do I need to add the CCK field to contexts? And if so, a little direction would be appreciated. Thanks.

Comments

Should be possible

itangalo's picture

The approach should work, so I guess there is a minor error in the snippet you pasted (but I can't see where).

There is an easier approach, though. The CCK fields are actually available as keywords/tokens, so you should be able to make direct string comparisons. I didn't know that CCK tokens were available, since they aren't listed, but found out at this issue: http://drupal.org/user/150069

The patterns for using CCK field tokens is

<?php
node
:field_name-formatted] (or [%node:field_name-raw]).


It is <em>also</em> possible to use tokens inside PHP code, if that should be necessary. This means that you could run checks like
<?php
 
return ([%node:field_landing_page_type-formatted] == 'Info Both');
?>

Good luck!
//Johan Falk, NodeOne, Sweden

Panels

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: