2

We have the requirement to make a trimmed back version of the website, for use for other websites to embed via an iframe. For instance, there will be no left navigation, no global navigation, and all elements will be re-flowed to fit in a smaller width.

I would like to do this with a separate theme (more than likely the iframed theme would be a sub theme of the main site theme).

What is the best way to ensure the site loads the alternative theme when it has been embedded (and switch back to the main theme when it is not)?

A thought I had:

  • Use a different sub-domain e.g. www.example.com and iframe.example.com

I am after what you think the best way to solve this would be

3 Answers 3

6

Create a custom module and put this lines there:

/** Implementation of hook_init **/
function yourmodule_init(&$vars) {

  //here put any condition to you want, for example a domain
  $url = url("<front>", array('absolute' => TRUE));
  if( $url == "http://mydomainiframe.com") {
    global $custom_theme;
    $custom_theme = 'new-theme'; //setting a new theme for this domain.
    init_theme();
  }
}

Also you can avoid create a whole new theme creating only a new page.tpl.php and using it.

/** preprocess_page **/
function your_module_preprocess_page(&$vars) {

  //here put any condition to you want, for example a domain
  $url = url("<front>", array('absolute' => TRUE));
  if( $url == "http://mydomainiframe.com") {
    $vars['template_file'] = 'page-iframe'; //setting a new page template
  }
}

And the page-iframe.tpl.php will be used instead of the page.tpl.php of your theme, in this way you can reuse things to you have in your actual theme.

3

Domain Access project is a suite of modules that provide tools for running a group of affiliated sites from one Drupal installation and a single shared database.
- this module commonly used for supporting multi-domains, and it can switch themes depend on current domain.

1

ThemeKey allows you to define simple or sophisticated theme-switching rules which allow automatic selection of a theme depending on current path, taxonomy terms, language, node-type, and many, many other properties. It can also be easily extended to support additional properties exposed by other modules. In combination with Drupal's theme inheritance you can easily achieve features like:

individually-styled channels
a front-page / "splash" screen
a date/time-selected Christmas theme
mobile themes for different auto-detected mobile devices
special themes for "limited" or "old" browsers
content, user, or role -specific themes
indicating your environment (production, staging, testing, sandbox, … )
testing your redesign safely on a live server
...

And unlike other theme switching modules, ThemeKey should play well with internal and external page caches, like Boost or Varnish, even for anonymous users.

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.