2004-04-13 08:46:28 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
|
|
<!-- $Revision$ -->
|
2005-05-10 21:14:36 +00:00
|
|
|
<sect1 id="language.function.assign">
|
2005-05-25 19:13:20 +00:00
|
|
|
<title>{assign}</title>
|
2005-09-13 19:03:11 +00:00
|
|
|
<para>
|
2006-09-26 02:02:55 +00:00
|
|
|
<varname>{assign}</varname> is used for assigning template variables
|
|
|
|
<emphasis role="bold">during the execution of a template</emphasis>.
|
2005-09-13 19:03:11 +00:00
|
|
|
</para>
|
2006-09-26 02:02:55 +00:00
|
|
|
|
2005-05-10 21:14:36 +00:00
|
|
|
<informaltable frame="all">
|
|
|
|
<tgroup cols="5">
|
|
|
|
<colspec colname="param" align="center" />
|
|
|
|
<colspec colname="type" align="center" />
|
|
|
|
<colspec colname="required" align="center" />
|
|
|
|
<colspec colname="default" align="center" />
|
|
|
|
<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>var</entry>
|
|
|
|
<entry>string</entry>
|
|
|
|
<entry>Yes</entry>
|
|
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
|
|
<entry>The name of the variable being assigned</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry>value</entry>
|
|
|
|
<entry>string</entry>
|
|
|
|
<entry>Yes</entry>
|
|
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
|
|
<entry>The value being assigned</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
2005-09-13 19:03:11 +00:00
|
|
|
|
2005-05-10 21:14:36 +00:00
|
|
|
<example>
|
2005-05-27 16:25:02 +00:00
|
|
|
<title>{assign}</title>
|
2005-05-10 21:14:36 +00:00
|
|
|
<programlisting>
|
|
|
|
<![CDATA[
|
2006-09-26 02:02:55 +00:00
|
|
|
{assign var='name' value='Bob'}
|
2004-04-13 08:46:28 +00:00
|
|
|
|
|
|
|
The value of $name is {$name}.
|
2005-05-10 21:14:36 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
<para>
|
|
|
|
The above example will output:
|
|
|
|
</para>
|
|
|
|
<screen>
|
|
|
|
<![CDATA[
|
|
|
|
The value of $name is Bob.
|
|
|
|
]]>
|
|
|
|
</screen>
|
|
|
|
</example>
|
2005-05-27 16:25:02 +00:00
|
|
|
|
2006-03-04 15:10:13 +00:00
|
|
|
<example>
|
|
|
|
<title>{assign} with some maths</title>
|
2006-09-26 02:02:55 +00:00
|
|
|
<para>This complex example must have the variables in `backticks`</para>
|
2006-03-04 15:10:13 +00:00
|
|
|
<programlisting>
|
|
|
|
<![CDATA[
|
2006-09-26 02:02:55 +00:00
|
|
|
{assign var=running_total value=`$running_total+$some_array[row].some_value`}
|
2006-03-04 15:10:13 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
|
|
|
|
</example>
|
2006-09-26 02:02:55 +00:00
|
|
|
|
2005-05-27 16:25:02 +00:00
|
|
|
<example>
|
2006-09-26 02:02:55 +00:00
|
|
|
<title>Accessing {assign} variables from a PHP script</title>
|
2005-05-27 16:25:02 +00:00
|
|
|
<para>
|
2006-09-26 02:02:55 +00:00
|
|
|
To access <varname>{assign}</varname> variables from a php script use
|
|
|
|
<link linkend="api.get.template.vars">
|
|
|
|
<varname>get_template_vars()</varname></link>.
|
|
|
|
Here's the template that creates the variable <parameter>$foo</parameter>.
|
2005-05-27 16:25:02 +00:00
|
|
|
</para>
|
|
|
|
<programlisting>
|
|
|
|
<![CDATA[
|
2006-09-26 02:02:55 +00:00
|
|
|
{assign var='foo' value='Smarty'}
|
2005-05-27 16:25:02 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
2006-09-26 02:02:55 +00:00
|
|
|
<para>The template variables are only available after/during template
|
|
|
|
execution as in the following script.
|
|
|
|
</para>
|
2005-05-27 16:25:02 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// this will output nothing as the template has not been executed
|
|
|
|
echo $smarty->get_template_vars('foo');
|
|
|
|
|
2006-09-26 02:02:55 +00:00
|
|
|
// fetch the template to a variable
|
|
|
|
$whole_page = $smarty->fetch('index.tpl');
|
2005-05-27 16:25:02 +00:00
|
|
|
|
|
|
|
// this will output 'smarty' as the template has been executed
|
|
|
|
echo $smarty->get_template_vars('foo');
|
|
|
|
|
|
|
|
$smarty->assign('foo','Even smarter');
|
|
|
|
|
|
|
|
// this will output 'Even smarter'
|
|
|
|
echo $smarty->get_template_vars('foo');
|
|
|
|
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following functions can also <emphasis>optionally</emphasis> assign
|
|
|
|
template variables.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2006-09-26 02:02:55 +00:00
|
|
|
<link linkend="language.function.capture"><varname>{capture}</varname></link>,
|
|
|
|
<link linkend="language.function.include"><varname>{include}</varname></link>,
|
|
|
|
<link linkend="language.function.include.php"><varname>{include_php}</varname></link>,
|
|
|
|
<link linkend="language.function.insert"><varname>{insert}</varname></link>,
|
|
|
|
<link linkend="language.function.counter"><varname>{counter}</varname></link>,
|
|
|
|
<link linkend="language.function.cycle"><varname>{cycle}</varname></link>,
|
|
|
|
<link linkend="language.function.eval"><varname>{eval}</varname></link>,
|
|
|
|
<link linkend="language.function.fetch"><varname>{fetch}</varname></link>,
|
|
|
|
<link linkend="language.function.math"><varname>{math}</varname></link>,
|
|
|
|
<link linkend="language.function.textformat"><varname>{textformat}</varname></link>
|
2005-05-27 16:25:02 +00:00
|
|
|
</para>
|
|
|
|
|
2005-05-23 15:43:01 +00:00
|
|
|
<para>
|
2006-09-26 02:02:55 +00:00
|
|
|
See also <link linkend="api.assign"><varname>assign()</varname></link>
|
2005-05-23 15:43:01 +00:00
|
|
|
and
|
2006-09-26 02:02:55 +00:00
|
|
|
<link linkend="api.get.template.vars"><varname>get_template_vars()</varname></link>.
|
2005-05-23 15:43:01 +00:00
|
|
|
</para>
|
2004-04-13 08:46:28 +00:00
|
|
|
</sect1>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|