<HTML ><HEAD ><TITLE >WAP/WML</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="Dates" HREF="tips.dates.html"><LINK REL="NEXT" TITLE="Componentized Templates" HREF="tips.componentized.templates.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.dates.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.componentized.templates.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="sect1" ><H1 CLASS="sect1" ><A NAME="tips.wap" ></A >WAP/WML</H1 ><P > WAP/WML templates require a php <A HREF="http://php.net/header" TARGET="_top" >Content-Type header</A > to be passed along with the template. The easist way to do this would be to write a custom function that prints the header. If you are using <A HREF="caching.html" >caching</A >, that won't work so we'll do it using the <A HREF="language.function.insert.html" ><TT CLASS="varname" >{insert}</TT ></A > tag; remember <TT CLASS="varname" >{insert}</TT > tags are not cached! Be sure that there is nothing output to the browser before the template, or else the header may fail. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN7677" ></A ><P ><B >Example 18-6. Using {insert} to write a WML Content-Type header</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// be sure apache is configure for the .wml extensions!<br />// put this function somewhere in your application, or in Smarty.addons.php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">insert_header</span><span style="color: #007700">(</span><span style="color: #0000BB">$params</span><span style="color: #007700">)<br />{<br /> </span><span style="color: #FF8000">// this function expects $content argument<br /> </span><span style="color: #007700">if (empty(</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">'content'</span><span style="color: #007700">])) {<br /> return;<br /> }<br /> </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #0000BB">$params</span><span style="color: #007700">[</span><span style="color: #DD0000">'content'</span><span style="color: #007700">]);<br /> return;<br />}<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></TD ></TR ></TABLE ><P > your Smarty template <SPAN CLASS="emphasis" ><I CLASS="emphasis" >must</I ></SPAN > begin with the insert tag : </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >{insert name=header content="Content-Type: text/vnd.wap.wml"} <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <!-- begin new wml deck --> <wml> <!-- begin first card --> <card> <do type="accept"> <go href="#two"/> </do> <p> Welcome to WAP with Smarty! Press OK to continue... </p> </card> <!-- begin second card --> <card id="two"> <p> Pretty easy isn't it? </p> </card> </wml></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.dates.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.componentized.templates.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Dates</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="tips.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Componentized Templates</TD ></TR ></TABLE ></DIV ></BODY ></HTML >