0

I am using the Zen theme, what I could like to do is effectly add a php include for a header area. This is common code so a block will not really do.

I have html.tpl.php which is added automatically to each page is there anyway to add custom chunks to every page for example myheader.tpl.php

4
  • Create a file with the code you want to include and include_once it into the template file.
    – user4035
    Mar 20, 2013 at 8:34
  • is that it? not a more drupal way
    – LeBlaireau
    Mar 20, 2013 at 8:54
  • You should tell us more about what you are trying to achieve - what does your common header code display or perform - if you want us to tell you how one would achieve that with Drupal. Mar 20, 2013 at 9:24
  • I just want a common bit of code, it does not really do anything and does not need to be edited by users
    – LeBlaireau
    Mar 21, 2013 at 6:17

2 Answers 2

0

You can try module_load_include

Loads a module include file.

Parameters

$type: The include file's type (file extension).

$module: The module to which the include file belongs.

$name: (optional) The base file name (without the $type extension). If omitted, $module is used; i.e., resulting in "$module.$type" by default.

Examples:

  // Load node.admin.inc from the node module.
  module_load_include('inc', 'node', 'node.admin');
  // Load content_types.inc from the node module.
  module_load_include('inc', 'node', 'content_types');
0

You rarely (probably never) want to pull in arbitrary PHP into a template. Generally you want all your processing to have happened before you reach this stage. The theme files should be 100% focused on generating markup.

If you are looking to do some processing on every page, you can use template_process_html(). Generally this is used to alter page variables before final render, or to add CSS and JS based on information from previous operations.

If you are looking to provide some output, you can add another region to your theme (or use a block in an existing region, but you've already passed over that concept).

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.