Question

I do load a panel (node_view) in a ct modal window. That works perfect so far. But now I need to load a specific variant of the panel.

I was playing with the handler stuff... but didn't get, yet.

How can I do this?

Here's my code for loading the panel programmactically:

function get_panel_view(&$node) {
    // Load my task plugin
    $task = page_manager_get_task('node_view');

    // Load the node into a context.
    ctools_include('context');
    ctools_include('context-task-handler');

    $contexts = ctools_context_handler_get_task_contexts($task, '', array($node));

    $output = ctools_context_handler_render($task, '', $contexts, array($node->nid));
    if ($output !== FALSE) {
       return $output;
       //return drupal_render($output['content']);
    }
    // Otherwise, fall back.
    return drupal_render(node_view(node_load($node->nid)));
}
Was it helpful?

Solution

The function ctools_context_handler_render_handler() does the trick, e.g.:

  1. First you need to get all handler objects of the given panel, e.g.

      $handlers = page_manager_load_sorted_handlers($task, '', TRUE);
    
  2. Specify your handler (variant), which you want to display, e.g.

    $handler = $handlers['node_view_panel_context_3'];
    
  3. Now we got all needed arguments to fire the function:

    $output = ctools_context_handler_render_handler($task,'',$handler, $contexts, array($node->nid));
    

And now, the $output contains the variant (3) of my panel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top