Community Documentation

Embedding other pages in Drupal with PHP includes

Last updated March 17, 2011. Created by nealb13 on September 14, 2010.
Edited by arianek, Carolyn, rootwork, aspilicious. Log in to edit this page.

PHP and HTML includes allow you to edit HTML and PHP on one page and update every page that had the include. In Drupal, the path might change with different themes (example: sites/all/themes/yourtheme/includes/head.php)

With the $directory variable, you can easily call the path to your theme. You can create an includes folder, then add your include files in there.

Here's what your Drupal include call will look like:

<?php
include ($directory."/includes/head.php");
?>

Comments

won't work when you subtheme

So I did just that and then derived a subtheme from my theme. When I over-rode my page.tpl.php file (which has the includes) Drupal could not find the includes as it expected them to be local to the sub-theme. This was a problem in D6 that I hoped had been fixed in 7 and I really don't want to repeat code in more than one template if it can be included.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Designers/themers

Theming Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here