Textpattern tips, tutorials and code snippets

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="https://textpattern.tips" title="">TXP Tips</a> and the respective authors. Powered by <a href="https://textpattern.com" title="Textpattern">Textpattern</a>.</p> 

And in the page:

<div id="footer" class="clear">
<txp:output_form form="footer" />
</div>

5 Comments Comment feed

If you leave the copyright date as a number you will have to go in every year and change it, I prefer to use a little code to automate this.

<txp:php> print date(“Y”); </txp:php>

This will change the year shown each January 1st.

Hi Shayne, thanks for the excellent tip. I will update the code above to reflect your addition.

Thanks for the date code :-).

Just what I was looking for, Thanks! … Who decided to name “includes”, “forms” ?! Not to mention the misconception of HTML <form>‘s.

@Core Action – the name “forms” was created by Textpattern creator Dean Allen a few years ago. I forget the actual reason, maybe someone else remembers…

Add a comment

Use Textile help to style your comments