0

I have a theme called 'progressive'. It has a sub theme called 'progressive_sub'.

I'm trying to exclude items from being displayed from a particular page in D7 (latest as of 12.2.15).

I have the following useful files:

/sites/all/themes/progressive/progressive_sub/template.php

This contains:

<?php

/**
 * Implements hook_preprocess_page().
 */
function progressive_sub_preprocess_page(&$variables) {
  $path = request_path();

  if ($path = 'node/131') {
    unset($variables['page']['header']);
    unset($variables['page']['sidebar']);
    unset($variables['page']['footer']);
    unset($variables['page']['bottom']);
    unset($variables['page']['top']);
    unset($variables['page']['content_top']);
    unset($variables['page']['sidebar']);
    unset($variables['page']['bottom']);
    unset($variables['page']['footer']);
    $variables['theme_hook_suggestions'][] = 'page';
  }
}

You can see that I'm trying to remove a heap of regions from this page (page.tpl.php) template, in this case when /node/131 is called.

I also have:

/sites/all/themes/progressive/progressive_sub/templates/page.tpl.php

which has all the usual including:

<?php print render($page['content']); ?>

My problem is that I cannot get this page.tpl.php to load when I'm viewing /node/131

Is there something that I'm doing wrong?

  • Have you tested something simple in your sub theme to test it is working? – Alex Gill Feb 12 '15 at 16:22
0

Wy don't you just create a template with this name:

page--node--131.tpl

and then, rather than removing regions in your template_preprocess_page function, just do not print them in your new template.

A few other things:

In some cases where order matters you may consider adding the suggestion to the beginning of the array using array_unshift.

Making use of request_path() is not the best way to get the path. It returns the request url, which may or may not be the internal path (think aliases). Better to use menu_get_object.

  • Thanks. This was a much simpler suggestion which worked out. I appreciate your help. – njwrigley Feb 13 '15 at 7:17
0

This

if ($path = 'node/131')

should surely be

if ($path == 'node/131')

Nevertheless this should not affect use of page.tpl.php.

Is your subtheme working at all, do templates get loaded from subtheme at all?

Your path is /sites/all/themes/progressive/progressive_sub. Does that mean the parent theme is at /sites/all/themes/progressive? If so, maybe try to give the subtheme a separate folder.

  • /sites/all/themes/progressive is where the main theme is, and /sites/all/themes/progressive/progressive_sub is where the sub theme is. The theme works perfectly, all pages load as I'd expect. – njwrigley Feb 12 '15 at 16:05
  • from your code your page.tpl.php should be loaded with every page load since your if condition is always true. So if the page.tpl.php gets never loaded there might be something wrong with the subtheme. So check out first if any template in your subtheme get loaded at all. – Stefan Korn Feb 12 '15 at 16:26

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.