Loading and viewing a panel programmatically

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

Hi,

how can I print out a panel page with PHP? To be more precise, I have registered an url with hook_menu. My menu callback function should do nothing else but output a panel page as if the user directly entered the url of the panel.

For nodes this would be done with node_load and node_view. Any hints how this can be done for panels?

Thank you!

Comments

I'm exactly at same place...

mbria's picture

Please, post here if you found a solution.

I'm exactly at this same place... so tomorrow I will start to review panels code to see how are called by the module preview or so.

Subscribing, I'd really like

shrikeh's picture

Subscribing, I'd really like to be able to hand panels the arguments it needs after my module sorts them out first.

Half solved

mbria's picture

Take a look at:
http://drupal.org/node/653584
http://drupal.org/node/685270

It's a partial solution, but take in consideration that we still don't know how to load correctly the panel if it includes a "view style" as viewscarousel, views_cycle and so on.

We tested it with panel-nodes and panel-pages but we didn't succed.
We finally fixed it in our project (based on OpenAtrium profile) dealing with templates, but looks like some page preprocess need to be done and is not.

I found it

hannanxp's picture

Try to use page_manager_page_execute.

for example, I have "Custom" panel page with the name "page-home_domain_19", this code works for me:

<?php
  module_load_include
("inc", "page_manager", "plugins/tasks/page");
 
 
$subtask_id = "home_domain_19";
 
$output = page_manager_page_execute($subtask_id);
?>

Panels mini

sime's picture

If you are just wanting to render a panel in response to a URL, have a look at how panels_mini.module renders a panel as a block in panels_mini_block_view().

Drupal 7 - load and render mini-panel, with context

timmarwick's picture

Drupal 7 - load and render mini-panel, with context:

<?php
  $delta
= 'my_mini_panel';
 
$panel_mini = panels_mini_load($delta);

 
ctools_include('context');
 
$context = ctools_context_create('entity:node', $node);
 
$contexts = ctools_context_match_required_contexts($panel_mini->requiredcontexts, array($context));
 
$panel_mini->context = $panel_mini->display->context ctools_context_load_contexts($panel_mini, FALSE, $contexts);
 
$panel_mini->display->css_id = panels_mini_get_id($panel_mini->name);
 
 
// Here is the markup, to with with whatever you wish.
 
$markup = panels_render_display($panel_mini->display);
?>
  • Note: first arg for ctools_context_create() is -- $type: The type of context to create; this loads a plugin.
    For entities in general, this seems to be 'entity:ENTITY_TYPE'.

Thank you exactly what I

dajjen's picture

Thank you exactly what I needed. In my case I render a mini panel with a form so I send $markup to render() function to get the markup.

<?php
  $delta
= 'my_mini_panel';
 
$panel_mini = panels_mini_load($delta);

 
ctools_include('context');
 
$context = ctools_context_create('entity:node', $node);
 
$contexts = ctools_context_match_required_contexts($panel_mini->requiredcontexts, array($context));
 
$panel_mini->context = $panel_mini->display->context ctools_context_load_contexts($panel_mini, FALSE, $contexts);
 
$panel_mini->display->css_id = panels_mini_get_id($panel_mini->name);
 
 
// Here is the markup, to with with whatever you wish.
 
$rendered_array = panels_render_display($panel_mini->display);
 
$markup = render($rendered_array);
?>

Best regards
David Park
Wunderkraut

Panels

Group organizers

Group notifications

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