Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drupal separating template code header and footer with include

I'm creating a drupal template and tried using this

    <?php require "".base_path() . path_to_theme()."'/header.php'" ?>

and it does provide the right path, but it gave this

Warning: require(/learn/learn_drupal/sites/all/themes/test_theme'/header.php'): failed to open stream: No such file or directory in require() (line 33 of /Users/Devric/Sites/learn/learn_drupal/sites/all/themes/test_theme/templates/html.tpl.php).

anyone know how to separate the code?

like image 900
devric Avatar asked Feb 22 '23 10:02

devric


1 Answers

If I were you I'd read up on how to set a proper Drupal theme.

Start by building a templates folder in your theme directory. Then copy over from the root modules/system/page.tpl.php and modules/system/html.tpl.php to this new templates folder.

This is your main theme files. html.tpl.php contains everything in your header (meta tags etc) and your start and end body tags.

page.tpl.php is what goes in between the body, or basically what is printed where it says <?php print $page; ?>.

If you open the page.tpl.php file you'll see all your regions etc. This is your page outline. Use this as to sort out any footers, headers etc using either hard code or Drupal's excellent block system.

If you think of your page like this is should help:

html.tpl.php -> opens your html page
   - page.tpl.php -> any constant elements above the content
      - node.tpl.php -> the content
   - page.tpl.php -> any constant elements below the content
html.tpl.php -> closes your html page

You don't need to set up your own includes because Drupal already does all this for you. It's a steep learning curve and I really struggled to start off with but there's no point not doing things the Drupal way as you're losing what makes it such a good CMS.

You can read more here - http://drupal.org/documentation/theme

EDIT:

You can set up blocks to be page specific and then theme them. Set up a block called about header for example and set to only be displayed on the pages you want it on in the blocks admin page. You can set templates up for each block in the same way you do nodes.

like image 155
SpaceBeers Avatar answered May 09 '23 13:05

SpaceBeers