I am using a multi-site set up, but the same problem could occur for a single site.

My set up is:

Multisite global theme:
- html.tpl.php
- - page.tpl.php

Subsite theme:
- - - page--node--2.tpl.php
- - - page--node--3.tpl.php

Page--node--n.tpl.php both have a lot of custom, non-Drupal PHP in.

What I want to achieve:

I have custom regions in the header of page.tpl.php and I want to keep modifications of the custom header in one place. Currently, page--node--n.tpl.php also contains the code for the header, and so any mods to page need to be copy and pasted to page-node-n, which is obviously bad practice.

Possible solutions:

  1. Move the everything that's truly universal (everything but the sidebars and content) from page to html in the global theme. This seems wrong, but is there any problem with this?
  2. Move the header and footer to separate PHP files and require them, pretty bad.
  3. Actually add the custom PHP in to the content of the Drupal Page Content (edit: or block visible on only that page), probably the worst, don't want to enable PHP Input Filter.
  4. Just keep copy and pasting


nevets’s picture

What makes the Page--node--n.tpl.php different?

Could the custom PHP be implemented as a block and placed in a region that exists in page.tpl.php? I find that often custom page--*.tpl.php are not really need with a bit of planning.

danoprey’s picture

Page--node--n.tpl.php are doing queries to a MongoDB on a site completely separate from these Drupal installations.

I considered the block idea, similar to just adding inside the page content for that node, but I really want to avoid enabling the PHP input filter. Aside from being a security threat, I have had issues with it jamming the cron before and want to keep this site clean.

nevets’s picture

Not sure where cron fits in but you could create a module that implements the blocks avoiding the need to use the PHP filter. Or you could implement hook_preprocess_page() and place your custom code there setting variables that can be printed in page.tpl.php. The point is, there are Drupal ways of achieve what you want without resorting to multiple page--*.tpl.php files.