Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > by-pkgid > 8377d4bb25a3992aad680df2952f4b71 > files > 145

php-smarty-doc-2.6.26-1mdv2010.0.noarch.rpm

<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 &#38; 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
>&#13;    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"
>&#13;    <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
>&#13;    <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
>&#13;    <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
>&#13;    <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"
>&#60;html&#62;
&#60;head&#62;
&#60;title&#62;{$title|default:'Smarty News'}&#60;/title&#62;
&#60;/head&#62;
&#60;body&#62;</PRE
></TD
></TR
></TABLE
><P
>&#13;    <TT
CLASS="filename"
>footer.tpl</TT
>
    </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>&#60;/body&#62;
&#60;/html&#62;</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
>