Being able to preview a panel prior to save is a great feature.

However the current preview uses the backend admin theme so doesn't accurately reflect the look of the panel on the frontend.

I wanted to set the theme to the frontend theme for the preview page.

I tried using hook_custom_theme but that gets overridden by panels or some other module later.

So, I ended up using the second recommended approach of hook_menu_alter which is working nicely.

Just thought I'd share in case anyone else was looking for this.

I'm not sure how this would fit into a patch, but is useful nonetheless.

<?php
/**
 * hook_menu_alter
 */
function example_menu_alter(&$items){
  // Add own theme callback to panels admin page for override
  $items['admin/structure/pages/%ctools_js/operation/%page_manager_cache']['theme callback'] = 'example_preview_theme';
}

/**
 * Custom theme callback for panels preview
 */
function example_preview_theme(){
  $args = arg();
  // If last URL argument is preview, then set frontend default theme
  if( array_pop($args) == 'preview' ){
    return variable_get('theme_default', 'bartik');
  }
}
?>

Thanks again for the awesome module,

DT

Comments

Silicon.Valet’s picture

Issue summary: View changes

We've done some work here https://www.drupal.org/node/2319517 to provide theme selection for preview, and to launch the preview in a separate window (so as to preserve DOM fidelity and theme isolation).

Would appreciate seeing if this fit your use case as well, as this would provide more endorsement of the approach.