Creating Header and Footer includes

One of the great things about Textpattern is its use of forms. Although the name is somewhat misunderstood, think of forms as if they were includes.

In this example, we create header and footer forms which are then outputted in your page templates. Make any future changes to your header/footer forms, and the results are automatically included in your site.

Create a form called header

Create a form called “header”, and assign it type “misc”. Enter the following code (which is from the TXP Tips site):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<!-- Meta -->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-gb" />
<meta name="robots" content="all" />
<meta name="revisit-after" content="3 days" />
<meta name="author" content="TXP Tips" />
<meta name="copyright" content="TXP Tips and Jonathan Stubbs" />
<meta name="description" content="Textpattern Tips - code clips, tutorials and code for the Textpattern CMS" />
<meta name="keywords" content="Textpattern, TXP, Tips, Clips, TXP Tips, TXP clips, CSS" />
<!-- Feeds -->
<txp:feed_link flavor="atom" format="link" label="Atom" />
<txp:feed_link flavor="rss" format="link" label="RSS" />
<!-- CSS -->
<txp:css n="default" format="link" />
<title><txp:page_title /></title>

Note that the form does not have a closing <head> tag. I prefer it this way because I then have the freedom to add anything else I want to in the page template.

Go to your page

In your page, enter the following:

<txp:output_form form="header" />
</head>

That’s it! Very simple and easy method to create easily updated header and footer includes.

For the sake of completeness, here is the footer form from the TXP Tips site:

<p>&copy; Copyright <txp:php> print date("Y"); </txp:php> <a href="http://txptips.com" title="">TXP Tips</a> and the respective authors. Powered by <a href="http://textpattern.com" title="Textpattern">Textpattern</a>.</p> 

And in the page:

<div id="footer" class="clear">
<txp:output_form form="footer" />
</div>
comments powered by Disqus