Im trying to make a selection rule for variants in Page manger and it includes some data comparison so it has to be in php. My field data is inside the context, so the $contexts variable can be used, but I cant get the proper way to use it. In my case it is a field value of the node, that is specified by the argument in URL "node/%nid".

Can some body please give an example code to extract the field value from context in php?

  • 1
    In my case this code became suitable solution $value = ctools_context_keyword_substitute('%node:field-proj-status', array(), $contexts)
    – ijujym
    Mar 7, 2012 at 22:56
  • The code above will work but it'll also give you Watchdog errors as per drupal.org/node/1781086
    – danbohea
    May 29, 2013 at 11:22

2 Answers 2


First of all, I want to point out that since this issue got closed in December, ctools got much better support for handling fields in access rules.

With that said, $contexts, have a data value, which is either an object, or an array of objects, depending on whether your plugin requires one or more contexts.

To make the code easier to read, I usually do something like this: $node = $context->data;

Brief example code:

function contact_info_pane_content_type_render($subtype, $conf, $args, $context = NULL) {
  $block = new stdClass;
  $block->content = '';
  $node = $context->data;
  $block->content .= count($node->field_email) > 0) ? $node->field_event_mail['und'][0]['email'] : '';
  $block->content .= count($node->field_phonenumber) > 0) ? $node->field_event_phonenumber['und'][0]['safe_value'] : '';

  return $block;

panels php https://drupal.org/sandbox/rogical/2121111

This module would solve this issue

  • Welcome to Drupal Answers! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – mpdonadio
    Oct 26, 2013 at 16:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.