I am reading through the API of the drupal 7 context module, and searching for examples, but I can't find a working example of how to programmatically test if a context is active for the current page.

I tried to call the context_isset() function defined in context.module, but what are the namespace and the attribute values? I only know about the context name and it's tag.


What can be done is to use the context_active_contexts() function.

Sample code, to see if the is_iframe context is active for the current page:

$contexts = context_active_contexts();
if (array_key_exists('is_iframe', $contexts)) : 
    watchdog('te','context is_iframe is set');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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