mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-27 18:31:36 +01:00
More formatting and cleaning up examples
This commit is contained in:
@@ -3,11 +3,10 @@
|
||||
<sect1 id="language.function.assign">
|
||||
<title>{assign}</title>
|
||||
<para>
|
||||
{assign} is used for assigning template variables
|
||||
<emphasis role="bold">during the execution
|
||||
of a template</emphasis>.
|
||||
<varname>{assign}</varname> is used for assigning template variables
|
||||
<emphasis role="bold">during the execution of a template</emphasis>.
|
||||
</para>
|
||||
|
||||
|
||||
<informaltable frame="all">
|
||||
<tgroup cols="5">
|
||||
<colspec colname="param" align="center" />
|
||||
@@ -47,7 +46,7 @@
|
||||
<title>{assign}</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{assign var="name" value="Bob"}
|
||||
{assign var='name' value='Bob'}
|
||||
|
||||
The value of $name is {$name}.
|
||||
]]>
|
||||
@@ -64,29 +63,31 @@ The value of $name is Bob.
|
||||
|
||||
<example>
|
||||
<title>{assign} with some maths</title>
|
||||
<para>This complex example must have the variables in backticks</para>
|
||||
<para>This complex example must have the variables in `backticks`</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{assign var=running_total value=`$running_total+$some_array[loop].some_value`}
|
||||
{assign var=running_total value=`$running_total+$some_array[row].some_value`}
|
||||
]]>
|
||||
</programlisting>
|
||||
|
||||
</example>
|
||||
|
||||
|
||||
<example>
|
||||
<title>Accessing {assign} variables from a PHP script.</title>
|
||||
<title>Accessing {assign} variables from a PHP script</title>
|
||||
<para>
|
||||
To access {assign} variables from the php script use
|
||||
<link linkend="api.get.template.vars">get_template_vars()</link>.
|
||||
However, the variables are only available after/during template execution
|
||||
as in the following example
|
||||
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>.
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* index.tpl *}
|
||||
{assign var="foo" value="Smarty"}
|
||||
{assign var='foo' value='Smarty'}
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>The template variables are only available after/during template
|
||||
execution as in the following script.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
@@ -94,8 +95,8 @@ The value of $name is Bob.
|
||||
// this will output nothing as the template has not been executed
|
||||
echo $smarty->get_template_vars('foo');
|
||||
|
||||
// fetch the template to a dead variable
|
||||
$dead = $smarty->fetch('index.tpl');
|
||||
// fetch the template to a variable
|
||||
$whole_page = $smarty->fetch('index.tpl');
|
||||
|
||||
// this will output 'smarty' as the template has been executed
|
||||
echo $smarty->get_template_vars('foo');
|
||||
@@ -117,22 +118,22 @@ echo $smarty->get_template_vars('foo');
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<link linkend="language.function.capture">{capture}</link>,
|
||||
<link linkend="language.function.include">{include}</link>,
|
||||
<link linkend="language.function.include.php">{include_php}</link>,
|
||||
<link linkend="language.function.insert">{insert}</link>,
|
||||
<link linkend="language.function.counter">{counter}</link>,
|
||||
<link linkend="language.function.cycle">{cycle}</link>,
|
||||
<link linkend="language.function.eval">{eval}</link>,
|
||||
<link linkend="language.function.fetch">{fetch}</link>,
|
||||
<link linkend="language.function.math">{math}</link>,
|
||||
<link linkend="language.function.textformat">{textformat}</link>
|
||||
<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>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
See also <link linkend="api.assign">assign()</link>
|
||||
See also <link linkend="api.assign"><varname>assign()</varname></link>
|
||||
and
|
||||
<link linkend="api.get.template.vars">get_template_vars()</link>.
|
||||
<link linkend="api.get.template.vars"><varname>get_template_vars()</varname></link>.
|
||||
</para>
|
||||
</sect1>
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
||||
Reference in New Issue
Block a user