<HTML ><HEAD ><TITLE >Passing variable title to header template</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Smarty Manual" HREF="index.html"><LINK REL="UP" TITLE="Tips & Tricks" HREF="tips.html"><LINK REL="PREVIOUS" TITLE="Default Variable Handling" HREF="tips.default.var.handling.html"><LINK REL="NEXT" TITLE="Dates" HREF="tips.dates.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="sect1" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Smarty Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="tips.default.var.handling.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Chapter 18. Tips & Tricks</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="tips.dates.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="tips.passing.vars" ></A >Passing variable title to header template</H1 ><P > When the majority of your templates use the same headers and footers, it is common to split those out into their own templates and <A HREF="language.function.include.html" > <TT CLASS="varname" >{include}</TT ></A > them. But what if the header needs to have a different title, depending on what page you are coming from? You can pass the title to the header as an <A HREF="language.syntax.attributes.html" >attribute</A > when it is included. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7616" ></A ><P ><B >Example 18-3. Passing the title variable to the header template</B ></P ><P > <TT CLASS="filename" >mainpage.tpl</TT > - When the main page is drawn, the title of <SPAN CLASS="QUOTE" >"Main Page"</SPAN > is passed to the <TT CLASS="filename" >header.tpl</TT >, and will subsequently be used as the title. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >{include file='header.tpl' title='Main Page'} {* template body goes here *} {include file='footer.tpl'}</PRE ></TD ></TR ></TABLE ><P > <TT CLASS="filename" >archives.tpl</TT > - When the archives page is drawn, the title will be <SPAN CLASS="QUOTE" >"Archives"</SPAN >. Notice in the archive example, we are using a variable from the <TT CLASS="filename" >archives_page.conf</TT > file instead of a hard coded variable. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >{config_load file='archive_page.conf'} {include file='header.tpl' title=#archivePageTitle#} {* template body goes here *} {include file='footer.tpl'}</PRE ></TD ></TR ></TABLE ><P > <TT CLASS="filename" >header.tpl</TT > - Notice that <SPAN CLASS="QUOTE" >"Smarty News"</SPAN > is printed if the <TT CLASS="literal" >$title</TT > variable is not set, using the <A HREF="language.modifier.default.html" ><TT CLASS="varname" >default</TT ></A > variable modifier. </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><html> <head> <title>{$title|default:'Smarty News'}</title> </head> <body></PRE ></TD ></TR ></TABLE ><P > <TT CLASS="filename" >footer.tpl</TT > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ></body> </html></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="tips.default.var.handling.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="tips.dates.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Default Variable Handling</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="tips.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Dates</TD ></TR ></TABLE ></DIV ></BODY ></HTML >