mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 11:24:27 +02:00
added header custom function
This commit is contained in:
@@ -273,6 +273,16 @@ function smarty_func_html_select_date()
|
|||||||
print $html_result;
|
print $html_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*======================================================================*\
|
||||||
|
Function: smarty_func_header
|
||||||
|
Purpose: Pass a header. Must be used before any content is sent.
|
||||||
|
\*======================================================================*/
|
||||||
|
function smarty_func_header($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
header($contents);
|
||||||
|
}
|
||||||
|
|
||||||
/* vim: set expandtab: */
|
/* vim: set expandtab: */
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@@ -76,7 +76,8 @@ class Smarty
|
|||||||
|
|
||||||
|
|
||||||
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
||||||
'html_select_date' => 'smarty_func_html_select_date'
|
'html_select_date' => 'smarty_func_html_select_date',
|
||||||
|
'header' => 'smarty_func_header'
|
||||||
);
|
);
|
||||||
|
|
||||||
var $custom_mods = array( 'lower' => 'strtolower',
|
var $custom_mods = array( 'lower' => 'strtolower',
|
||||||
|
74
docs.sgml
74
docs.sgml
@@ -1711,8 +1711,7 @@ OUTPUT:
|
|||||||
<title>Custom Functions</title>
|
<title>Custom Functions</title>
|
||||||
<para>
|
<para>
|
||||||
Custom functions in Smarty work much the same as the built-in functions
|
Custom functions in Smarty work much the same as the built-in functions
|
||||||
syntactically. Two custom functions come bundled with Smarty. You can
|
syntactically.
|
||||||
also write your own.
|
|
||||||
</para>
|
</para>
|
||||||
<sect2>
|
<sect2>
|
||||||
<title>html_options</title>
|
<title>html_options</title>
|
||||||
@@ -1736,14 +1735,14 @@ OUTPUT:
|
|||||||
<row>
|
<row>
|
||||||
<entry>values</entry>
|
<entry>values</entry>
|
||||||
<entry>array</entry>
|
<entry>array</entry>
|
||||||
<entry>No, if using options attribute</entry>
|
<entry>Yes, unless using options attribute</entry>
|
||||||
<entry><emphasis>n/a</emphasis></entry>
|
<entry><emphasis>n/a</emphasis></entry>
|
||||||
<entry>an array of values for dropdown</entry>
|
<entry>an array of values for dropdown</entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry>output</entry>
|
<entry>output</entry>
|
||||||
<entry>array</entry>
|
<entry>array</entry>
|
||||||
<entry>No, if using options attribute</entry>
|
<entry>Yes, unless using options attribute</entry>
|
||||||
<entry><emphasis>n/a</emphasis></entry>
|
<entry><emphasis>n/a</emphasis></entry>
|
||||||
<entry>an array of output for dropdown</entry>
|
<entry>an array of output for dropdown</entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -1757,7 +1756,7 @@ OUTPUT:
|
|||||||
<row>
|
<row>
|
||||||
<entry>options</entry>
|
<entry>options</entry>
|
||||||
<entry>associative array</entry>
|
<entry>associative array</entry>
|
||||||
<entry>No, if using values and output</entry>
|
<entry>Yes, unless using values and output</entry>
|
||||||
<entry><emphasis>n/a</emphasis></entry>
|
<entry><emphasis>n/a</emphasis></entry>
|
||||||
<entry>an associative array of values and output</entry>
|
<entry>an associative array of values and output</entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -1996,6 +1995,71 @@ OUTPUT:
|
|||||||
<option value="2001">2001</option>
|
<option value="2001">2001</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect2>
|
||||||
|
<sect2>
|
||||||
|
<title>header</title>
|
||||||
|
<informaltable frame=all>
|
||||||
|
<tgroup cols=3>
|
||||||
|
<colspec colname=param>
|
||||||
|
<colspec colname=type>
|
||||||
|
<colspec colname=required>
|
||||||
|
<colspec colname=default>
|
||||||
|
<colspec colname=desc>
|
||||||
|
<thead>
|
||||||
|
<row>
|
||||||
|
<entry>Attribute Name</entry>
|
||||||
|
<entry>Type</entry>
|
||||||
|
<entry>Required</entry>
|
||||||
|
<entry>Default</entry>
|
||||||
|
<entry>Description</entry>
|
||||||
|
</row>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<row>
|
||||||
|
<entry>contents</entry>
|
||||||
|
<entry>string</entry>
|
||||||
|
<entry>Yes</entry>
|
||||||
|
<entry><emphasis>n/a</emphasis></entry>
|
||||||
|
<entry>The contents of the header to pass</entry>
|
||||||
|
</row>
|
||||||
|
</tbody>
|
||||||
|
</tgroup>
|
||||||
|
</informaltable>
|
||||||
|
<para>
|
||||||
|
<emphasis>header</emphasis> is a function that passes a raw header
|
||||||
|
string to the output. If your template is used for WAP (Wireless
|
||||||
|
Access Protocol) for example, you would need to send a special
|
||||||
|
header to indicate the type of content you are sending.
|
||||||
|
</para>
|
||||||
|
<para>
|
||||||
|
TECHNICAL NOTE: Be sure you call {header ...}
|
||||||
|
<emphasis>before</emphasis> any output in your template, in
|
||||||
|
including whitespace. Otherwise the header will not work as
|
||||||
|
intended.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>header</title>
|
||||||
|
<programlisting>
|
||||||
|
|
||||||
|
{* our template is outputting contents for WAP devices *}
|
||||||
|
{header contents="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"
|
||||||
|
|
||||||
|
<wml>
|
||||||
|
<card id="card1" title="Example1">
|
||||||
|
<p>
|
||||||
|
{$now|date_format}
|
||||||
|
Welcome to my webpage!
|
||||||
|
</p>
|
||||||
|
</card>
|
||||||
|
</wml>
|
||||||
|
|
||||||
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
@@ -76,7 +76,8 @@ class Smarty
|
|||||||
|
|
||||||
|
|
||||||
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
var $custom_funcs = array( 'html_options' => 'smarty_func_html_options',
|
||||||
'html_select_date' => 'smarty_func_html_select_date'
|
'html_select_date' => 'smarty_func_html_select_date',
|
||||||
|
'header' => 'smarty_func_header'
|
||||||
);
|
);
|
||||||
|
|
||||||
var $custom_mods = array( 'lower' => 'strtolower',
|
var $custom_mods = array( 'lower' => 'strtolower',
|
||||||
|
Reference in New Issue
Block a user