1

In my theme, I have page.tpl.php and page--node--1.tpl.php.

When page--node--1.tpl.php is rendered, everything in page.tpl.php is lost. I only want page--code--1.tpl.php to replace the $content line in page.tpl.php and inherit everything else in page.tpl.php.

How can I do this? Do I need to first create a template for the content type?

Below is what I have in my template.php

if (strtolower($vars['template_files'][0]) == "page-search") {
    $vars["template_files"] = array();
    $vars["template_files"][] = 'page-search';
} else {
    if ($vars["template_files"][2] != 'page-node-edit') {
        if (isset($vars['node']) && ($vars['node']->type == "mytheme_page" || $vars['node']->type == "person" || $vars['node']->type == "blank_page")) {
            if ($vars["template_files"][2] == "page-front") {
                $vars["template_files"] = array();
                $vars["template_files"][] = 'page-home-mytheme';
            } else {
                $vars["template_files"] = array();
                if ($vars['node']->type == "blank_page") {
                    $vars["template_files"][] = 'page-blank';
                } else {
                    //print "made it here";exit;                
                    $vars["template_files"][] = 'page-mytheme';
                }
            }
        } elseif ($alias == "sitemap") {
            $vars["template_files"] = array();
            $vars["template_files"][] = 'page-blank';
        }
    }
}
  • Duplicate the page.tpl.php code and only change the content line, keeping all the remaining code. – Patrick Ryan Apr 23 '15 at 20:51
  • This did not work. It stopped showing my logo, menus etc. – srodrig Apr 23 '15 at 21:00
  • You need to define a preprocess_page() template function in your theme template.php and override node pages as per the URL you are trying to access them. – Prerit Mohan Apr 24 '15 at 5:53
  • Thank Prerit. I updated my question to show what I have in my template.php. I still don't quite understand why the content is not showing. Currently I am using page.tpl, node.tpl and node-1.tpl. The themer module shows all templates rendering but only the HTML in node-1 shows, not the actual content that was entered into the fields on the admin side. – srodrig Apr 27 '15 at 12:44
1

You cannot do this with those templates.

Only one "page" template will be used. You could try using one "page" template, and one "node" template: https://api.drupal.org/api/drupal/modules!node!node.tpl.php/7

but the node template won't allow you to modify the page template.

  • So I created a separate node.tpl.php. And a node--1.tpl.php. It seems I am headed in the right direction? I see the page render page.tpl, node.tpl and node-1.tpl. But some of my content, such as images, doesn't render like they were when I was just using page.tpl – srodrig Apr 23 '15 at 20:59

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.