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.