3

I have copied the simple-layout files and customized, the custom layout is simply mats2015.simple-layout (mats2015.simple-layout.tpl.php). I need to override this file for a specific content type (plain-page).

Before Omega 4 (and using the layouts extension) I would use the following:

  • In theme_alpha_preprocess_html(): $variables['theme_hook_suggestions'] = array('html__plain_page_wrapper');

  • In theme_alpha_preprocess_page(): $variables['theme_hook_suggestions'] = array('html__plain_page');

And, together, those two template files (html_plain_page_wrapper.tpl.php, html__plain_page.tpl.php) would simply render $page['content'] and nothing else.

If, within mats2015.simple-layout.tpl.php I include get_defined_vars() I see this:

'omega_layout' => 
array (size=7)
  'name' => string 'mats2015.simple' (length=15)
  'path' => string 'sites/all/themes/mats2015/layouts/mats2015.simple' (length=49)
  'file' => string 'sites/all/themes/mats2015/layouts/mats2015.simple/mats2015.simple.layout.inc' (length=76)
  'info' => 
    array (size=4)
      'name' => string 'MATS 2015 Simple' (length=16)
      'description' => string 'preview = preview.png' (length=21)
      'template' => string 'mats2015.simple-layout' (length=22)
      'regions' => 
        array (size=11)
          ...
  'theme' => string 'mats2015' (length=8)
  'attached' => 
    array (size=0)
      empty
  'template' => string 'mats2015.simple-layout' (length=22)
  'theme_hook_suggestions' => 
    array (size=0)
      empty

So, the question is: is there a preprocess hook I'm missing that I can use to switch from mats2015.simple.tpl.php to some-other.tpl.php based on content type? Or is there a naming convention for the layout extension files that I'm missing?

Thanks!

6

So, I was able to accomplish this using the following:

tl;dr: Create another layout extension, and use theme_omega_layout_alter(&$layout) to switch. That's the preprocess function I had to track down.

(assuming use of included layout *simple-layout* and you want to create a layout for node type plain-page [the naming convention doesn't matter])

  1. Copy themes/_your-theme_/layouts/simple to themes/_your-theme_/layouts/plain.
  2. Modify the file names:
    • simple.layout.inc -> plain.layout.inc
    • simple-layout.tpl.php -> plain-layout.tpl.php
  3. Modify plain.layout.inc (It's just like a .info file for a theme, self-explanatory)
  4. Modify plain-layout.tpl.php to suit your needs (In my case, I need to remove everything except render($page['content']).
  5. Open themes/_your-theme_/template.php and add theme_omega_layout_alter(&$layout):

    // this is specific to my use case
    // change 'theme' to your theme name, as you would with any
    // preprocess function
    function theme_omega_layout_alter(&$layout) {
      $cPath = current_path();
      if (strpos($cPath, 'invite-print') !== 0) {
        $layout = 'plain';
      }
    }
    

The following is only necessary if you want to change parent structure (<html>, <head>, etc.), which I needed to

  1. Open themes/_your-theme_/preprocess/html.preprocess.inc and put this in:

     // this is specific to my use case
     // change 'theme' to your theme name, as you would with any
     // preprocess function
     function theme_preprocess_html(&$variables) {
       $cPath = current_path();
       if (strpos($cPath, 'invite-print') !== 0) {
         $variables['theme_hook_suggestions'][] = 'html__plain_page';
       }
     }
    
  2. Create /themes/_your-theme_/templates/html--plain-page.tpl.php and modify as necessary.

It felt like overkill for my situation (having to create entire new layouts) but I understand why it was done - it's crazy powerful for sites that need to make drastically different layouts for different pages. Think different regions, stylesheets, js, etc - completely different .info files, essentially.

Hope this helps someone!

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.