mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
clean two files
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
<example>
|
<example>
|
||||||
<title>Comments</title>
|
<title>Comments</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
{* Smarty *}
|
{* Smarty *}
|
||||||
|
|
||||||
{* include the header file here *}
|
{* include the header file here *}
|
||||||
@@ -36,9 +37,11 @@
|
|||||||
{include file=#includeFile#}
|
{include file=#includeFile#}
|
||||||
|
|
||||||
{* display dropdown lists *}
|
{* display dropdown lists *}
|
||||||
<SELECT name=company>
|
<select name="company">
|
||||||
{html_options values=$vals selected=$selected output=$output}
|
{html_options values=$vals selected=$selected output=$output}
|
||||||
</SELECT></programlisting>
|
</select>
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
|
|
||||||
@@ -99,6 +102,7 @@
|
|||||||
<example>
|
<example>
|
||||||
<title>function attribute syntax</title>
|
<title>function attribute syntax</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
{include file="header.tpl"}
|
{include file="header.tpl"}
|
||||||
|
|
||||||
{include file=$includeFile}
|
{include file=$includeFile}
|
||||||
@@ -107,106 +111,121 @@
|
|||||||
|
|
||||||
{html_select_date display_days=yes}
|
{html_select_date display_days=yes}
|
||||||
|
|
||||||
<SELECT name=company>
|
<select name="company">
|
||||||
{html_options values=$vals selected=$selected output=$output}
|
{html_options values=$vals selected=$selected output=$output}
|
||||||
</SELECT></programlisting>
|
</select>
|
||||||
</example>
|
]]>
|
||||||
</sect1>
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect1>
|
||||||
<sect1 id="language.syntax.quotes">
|
<sect1 id="language.syntax.quotes">
|
||||||
<title>Embedding Vars in Double Quotes</title>
|
<title>Embedding Vars in Double Quotes</title>
|
||||||
<para>
|
<para>
|
||||||
Smarty will recognize assigned variables embedded in double quotes so long
|
Smarty will recognize assigned variables embedded in double quotes so long
|
||||||
as the variables contain only numbers, letters, underscores and brackets
|
as the variables contain only numbers, letters, underscores and brackets
|
||||||
[]. With any other characters (period, object reference, etc.) the variable
|
[]. With any other characters (period, object reference, etc.) the variable
|
||||||
must be surrounded by backticks.
|
must be surrounded by backticks.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>embedded quotes syntax</title>
|
<title>embedded quotes syntax</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
SYNTAX EXAMPLES:
|
SYNTAX EXAMPLES:
|
||||||
{func var="test $foo test"} <-- sees $foo
|
{func var="test $foo test"} <-- sees $foo
|
||||||
{func var="test $foo_bar test"} <-- sees $foo_bar
|
{func var="test $foo_bar test"} <-- sees $foo_bar
|
||||||
{func var="test $foo[0] test"} <-- sees $foo[0]
|
{func var="test $foo[0] test"} <-- sees $foo[0]
|
||||||
{func var="test $foo[bar] test"} <-- sees $foo[bar]
|
{func var="test $foo[bar] test"} <-- sees $foo[bar]
|
||||||
{func var="test $foo.bar test"} <-- sees $foo (not $foo.bar)
|
{func var="test $foo.bar test"} <-- sees $foo (not $foo.bar)
|
||||||
{func var="test `$foo.bar` test"} <-- sees $foo.bar
|
{func var="test `$foo.bar` test"} <-- sees $foo.bar
|
||||||
|
|
||||||
PRACTICAL EXAMPLES:
|
PRACTICAL EXAMPLES:
|
||||||
{include file="subdir/$tpl_name.tpl"} <-- will replace $tpl_name with value
|
{include file="subdir/$tpl_name.tpl"} <-- will replace $tpl_name with value
|
||||||
{cycle values="one,two,`$smarty.config.myval`"} <-- must have backticks</programlisting>
|
{cycle values="one,two,`$smarty.config.myval`"} <-- must have backticks
|
||||||
</example>
|
]]>
|
||||||
</sect1>
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect1>
|
||||||
<sect1 id="language.math">
|
<sect1 id="language.math">
|
||||||
<title>Math</title>
|
<title>Math</title>
|
||||||
<para>
|
<para>
|
||||||
Math can be applied directly to variable values.
|
Math can be applied directly to variable values.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>math examples</title>
|
<title>math examples</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
{$foo+1}
|
{$foo+1}
|
||||||
|
|
||||||
{$foo*$bar}
|
{$foo*$bar}
|
||||||
|
|
||||||
{* some more complicated examples *}
|
{* some more complicated examples *}
|
||||||
|
|
||||||
{$foo->bar-$bar[1]*$baz->foo->bar()-3*7}
|
{$foo->bar-$bar[1]*$baz->foo->bar()-3*7}
|
||||||
|
|
||||||
{if ($foo+$bar.test%$baz*134232+10+$b+10)}
|
{if ($foo+$bar.test%$baz*134232+10+$b+10)}
|
||||||
|
|
||||||
{$foo|truncate:"`$fooTruncCount/$barTruncFactor-1`"}
|
{$foo|truncate:"`$fooTruncCount/$barTruncFactor-1`"}
|
||||||
|
|
||||||
{assign var="foo" value="`$foo+$bar`"}</programlisting>
|
{assign var="foo" value="`$foo+$bar`"}
|
||||||
</example>
|
]]>
|
||||||
</sect1>
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect1>
|
||||||
|
|
||||||
<sect1 id="language.escaping">
|
<sect1 id="language.escaping">
|
||||||
<title>Escaping Smarty Parsing</title>
|
<title>Escaping Smarty Parsing</title>
|
||||||
<para>
|
<para>
|
||||||
It is sometimes desirable or even necessary to have Smarty ignore sections it
|
It is sometimes desirable or even necessary to have Smarty ignore sections it
|
||||||
would otherwise parse. A classic example is embedding Javascript or CSS code in
|
would otherwise parse. A classic example is embedding Javascript or CSS code in
|
||||||
a template. The problem arises as those languages use the { and } characters
|
a template. The problem arises as those languages use the { and } characters
|
||||||
which are also the default delimiters for Smarty.
|
which are also the default delimiters for Smarty.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The simplest thing is to avoid the situation altogether by separating your Javascript
|
The simplest thing is to avoid the situation altogether by separating your Javascript
|
||||||
and CSS code into their own files and then using standard HTML methods to access them.
|
and CSS code into their own files and then using standard HTML methods to access them.
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Including literal content is possible using <link linkend="language.function.literal">{literal} .. {/literal}</link> blocks.
|
|
||||||
Similar to HTML entity usage, you can use <link linkend="language.function.ldelim">{ldelim}</link> and <link linkend="language.function.ldelim">{rdelim}</link>
|
|
||||||
to display the current delimiters.
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
It is often convenient to simply change Smarty's <link linkend="variable.left.delimiter">$left_delimiter</link> and
|
Including literal content is possible using <link
|
||||||
<link linkend="variable.right.delimiter">$right_delimiter</link>.
|
linkend="language.function.literal">{literal} .. {/literal}</link> blocks.
|
||||||
|
Similar to HTML entity usage, you can use <link
|
||||||
|
linkend="language.function.ldelim">{ldelim}</link> and <link
|
||||||
|
linkend="language.function.ldelim">{rdelim}</link> to display the current delimiters.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
It is often convenient to simply change Smarty's <link
|
||||||
|
linkend="variable.left.delimiter">$left_delimiter</link> and
|
||||||
|
<link linkend="variable.right.delimiter">$right_delimiter</link>.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>changing delimiters example</title>
|
<title>changing delimiters example</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->left_delimiter = '<!--{';
|
$smarty->left_delimiter = '<!--{';
|
||||||
$smarty->right_delimiter = '}-->';
|
$smarty->right_delimiter = '}-->';
|
||||||
$smarty->assign('foo', 'bar');
|
$smarty->assign('foo', 'bar');
|
||||||
$smarty->display('example.tpl');
|
$smarty->display('example.tpl');
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
--- example.tpl
|
--- example.tpl
|
||||||
<script language="javascript">
|
<script language="javascript">
|
||||||
var foo = <!--{$foo}-->;
|
var foo = <!--{$foo}-->;
|
||||||
function dosomething() {
|
function dosomething() {
|
||||||
alert("foo is " + foo);
|
alert("foo is " + foo);
|
||||||
}
|
}
|
||||||
dosomething();
|
dosomething();
|
||||||
</script>
|
</script>
|
||||||
|
]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
|
</sect1>
|
||||||
</sect1>
|
</chapter>
|
||||||
</chapter>
|
|
||||||
<!-- Keep this comment at the end of the file
|
<!-- Keep this comment at the end of the file
|
||||||
Local variables:
|
Local variables:
|
||||||
mode: sgml
|
mode: sgml
|
||||||
@@ -226,4 +245,4 @@ End:
|
|||||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||||
vim: et tw=78 syn=sgml
|
vim: et tw=78 syn=sgml
|
||||||
vi: ts=1 sw=1
|
vi: ts=1 sw=1
|
||||||
-->
|
-->
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
<chapter id="language.variables">
|
<chapter id="language.variables">
|
||||||
<title>Variables</title>
|
<title>Variables</title>
|
||||||
<para>
|
<para>
|
||||||
Smarty has several different types of variables. The type of the variable
|
Smarty has several different types of variables. The type of the variable
|
||||||
depends on what symbol it is prefixed with (or enclosed within).
|
depends on what symbol it is prefixed with (or enclosed within).
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
@@ -13,128 +13,169 @@
|
|||||||
etc. To print a variable, simply enclose it in the delimiters so that it
|
etc. To print a variable, simply enclose it in the delimiters so that it
|
||||||
is the only thing contained between them. Examples:
|
is the only thing contained between them. Examples:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
{$Name}
|
{$Name}
|
||||||
|
|
||||||
{$Contacts[row].Phone}
|
{$Contacts[row].Phone}
|
||||||
|
|
||||||
<body bgcolor="{#bgcolor#}"></programlisting>
|
<body bgcolor="{#bgcolor#}">
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<sect1 id="language.assigned.variables">
|
<sect1 id="language.assigned.variables">
|
||||||
<title>Variables assigned from PHP</title>
|
<title>Variables assigned from PHP</title>
|
||||||
<para>
|
<para>
|
||||||
Variables that are assigned from PHP are referenced by preceding them with
|
Variables that are assigned from PHP are referenced by preceding them with
|
||||||
a dollar sign <literal>$</literal>. Variables assigned from within the
|
a dollar sign <literal>$</literal>. Variables assigned from within the
|
||||||
template with the <link linkend="language.function.assign">assign</link>
|
template with the <link linkend="language.function.assign">assign</link>
|
||||||
function are also displayed this way.
|
function are also displayed this way.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
|
|
||||||
<title>assigned variables</title>
|
<title>assigned variables</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
Hello {$firstname}, glad to see you could make it.
|
Hello {$firstname}, glad to see you could make it.
|
||||||
<p>
|
<br />
|
||||||
Your last login was on {$lastLoginDate}.
|
Your last login was on {$lastLoginDate}.
|
||||||
|
]]>
|
||||||
OUTPUT:
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This will output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
Hello Doug, glad to see you could make it.
|
Hello Doug, glad to see you could make it.
|
||||||
<p>
|
<br />
|
||||||
Your last login was on January 11th, 2001.</programlisting>
|
Your last login was on January 11th, 2001.
|
||||||
</example>
|
]]>
|
||||||
|
</screen>
|
||||||
|
</example>
|
||||||
|
|
||||||
<sect2 id="language.variables.assoc.arrays">
|
<sect2 id="language.variables.assoc.arrays">
|
||||||
<title>Associative arrays</title>
|
<title>Associative arrays</title>
|
||||||
<para>
|
<para>
|
||||||
You can also reference associative array variables that are
|
You can also reference associative array variables that are
|
||||||
assigned from PHP by specifying the key after the '.' (period)
|
assigned from PHP by specifying the key after the '.' (period)
|
||||||
symbol.
|
symbol.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>accessing associative array variables</title>
|
<title>accessing associative array variables</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('Contacts',
|
$smarty->assign('Contacts',
|
||||||
array('fax' => '555-222-9876',
|
array('fax' => '555-222-9876',
|
||||||
'email' => 'zaphod@slartibartfast.com',
|
'email' => 'zaphod@slartibartfast.com',
|
||||||
'phone' => array('home' => '555-444-3333',
|
'phone' => array('home' => '555-444-3333',
|
||||||
'cell' => '555-111-1234')));
|
'cell' => '555-111-1234')));
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
?>
|
||||||
index.tpl:
|
]]>
|
||||||
|
</programlisting>
|
||||||
{$Contacts.fax}<br>
|
<para>
|
||||||
{$Contacts.email}<br>
|
where the content of index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{$Contacts.fax}<br />
|
||||||
|
{$Contacts.email}<br />
|
||||||
{* you can print arrays of arrays as well *}
|
{* you can print arrays of arrays as well *}
|
||||||
{$Contacts.phone.home}<br>
|
{$Contacts.phone.home}<br />
|
||||||
{$Contacts.phone.cell}<br>
|
{$Contacts.phone.cell}<br />
|
||||||
|
]]>
|
||||||
OUTPUT:
|
</programlisting>
|
||||||
|
<para>
|
||||||
555-222-9876<br>
|
this will output:
|
||||||
zaphod@slartibartfast.com<br>
|
</para>
|
||||||
555-444-3333<br>
|
<screen>
|
||||||
555-111-1234<br></programlisting>
|
<![CDATA[
|
||||||
</example>
|
555-222-9876<br />
|
||||||
|
zaphod@slartibartfast.com<br />
|
||||||
|
555-444-3333<br />
|
||||||
|
555-111-1234<br />
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
<sect2 id="language.variables.array.indexes">
|
<sect2 id="language.variables.array.indexes">
|
||||||
<title>Array indexes</title>
|
<title>Array indexes</title>
|
||||||
<para>
|
<para>
|
||||||
You can reference arrays by their index, much like native PHP
|
You can reference arrays by their index, much like native PHP
|
||||||
syntax.
|
syntax.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>accessing arrays by index</title>
|
<title>accessing arrays by index</title>
|
||||||
<programlisting>
|
<programlisting role="php">
|
||||||
index.php:
|
<![CDATA[
|
||||||
|
<?php
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
$smarty->assign('Contacts',
|
$smarty->assign('Contacts',
|
||||||
array('555-222-9876',
|
array('555-222-9876',
|
||||||
'zaphod@slartibartfast.com',
|
'zaphod@slartibartfast.com',
|
||||||
array('555-444-3333',
|
array('555-444-3333',
|
||||||
'555-111-1234')));
|
'555-111-1234')));
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
index.tpl:
|
?>
|
||||||
|
]]>
|
||||||
{$Contacts[0]}<br>
|
</programlisting>
|
||||||
{$Contacts[1]}<br>
|
<para>
|
||||||
|
where index.tpl is:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
{$Contacts[0]}<br />
|
||||||
|
{$Contacts[1]}<br />
|
||||||
{* you can print arrays of arrays as well *}
|
{* you can print arrays of arrays as well *}
|
||||||
{$Contacts[2][0]}<br>
|
{$Contacts[2][0]}<br />
|
||||||
{$Contacts[2][1]}<br>
|
{$Contacts[2][1]}<br />
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
This will output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
555-222-9876<br />
|
||||||
|
zaphod@slartibartfast.com<br />
|
||||||
|
555-444-3333<br />
|
||||||
|
555-111-1234<br />
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
|
</example>
|
||||||
|
</sect2>
|
||||||
|
<sect2 id="language.variables.objects">
|
||||||
|
<title>Objects</title>
|
||||||
|
<para>
|
||||||
|
Properties of objects assigned from PHP can be referenced
|
||||||
|
by specifying the property name after the '->' symbol.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>accessing object properties</title>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
name: {$person->name}<br />
|
||||||
|
email: {$person->email}<br />
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
this will output:
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
name: Zaphod Beeblebrox<br />
|
||||||
|
email: zaphod@slartibartfast.com<br />
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
|
</example>
|
||||||
|
</sect2>
|
||||||
|
</sect1>
|
||||||
|
|
||||||
OUTPUT:
|
<sect1 id="language.config.variables">
|
||||||
|
|
||||||
555-222-9876<br>
|
|
||||||
zaphod@slartibartfast.com<br>
|
|
||||||
555-444-3333<br>
|
|
||||||
555-111-1234<br></programlisting>
|
|
||||||
</example>
|
|
||||||
</sect2>
|
|
||||||
<sect2 id="language.variables.objects">
|
|
||||||
<title>Objects</title>
|
|
||||||
<para>
|
|
||||||
Properties of objects assigned from PHP can be referenced
|
|
||||||
by specifying the property name after the '->' symbol.
|
|
||||||
</para>
|
|
||||||
<example>
|
|
||||||
<title>accessing object properties</title>
|
|
||||||
<programlisting>
|
|
||||||
name: {$person->name}<br>
|
|
||||||
email: {$person->email}<br>
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
name: Zaphod Beeblebrox<br>
|
|
||||||
email: zaphod@slartibartfast.com<br></programlisting>
|
|
||||||
</example>
|
|
||||||
</sect2>
|
|
||||||
</sect1>
|
|
||||||
|
|
||||||
<sect1 id="language.config.variables">
|
|
||||||
<title>Variables loaded from config files</title>
|
<title>Variables loaded from config files</title>
|
||||||
<para>
|
<para>
|
||||||
Variables that are loaded from the config files are referenced by
|
Variables that are loaded from the config files are referenced by
|
||||||
@@ -144,92 +185,105 @@ email: zaphod@slartibartfast.com<br></programlisting>
|
|||||||
The second syntax is useful for embedding into quoted attribute
|
The second syntax is useful for embedding into quoted attribute
|
||||||
values.
|
values.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
|
<title>config variables</title>
|
||||||
<title>config variables</title>
|
<para>
|
||||||
<programlisting>
|
foo.conf:
|
||||||
foo.conf:
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
pageTitle = "This is mine"
|
pageTitle = "This is mine"
|
||||||
bodyBgColor = "#eeeeee"
|
bodyBgColor = "#eeeeee"
|
||||||
tableBorderSize = "3"
|
tableBorderSize = "3"
|
||||||
tableBgColor = "#bbbbbb"
|
tableBgColor = "#bbbbbb"
|
||||||
rowBgColor = "#cccccc"
|
rowBgColor = "#cccccc"
|
||||||
|
]]>
|
||||||
index.tpl:
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
index.tpl:
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
{config_load file="foo.conf"}
|
{config_load file="foo.conf"}
|
||||||
<html>
|
<html>
|
||||||
<title>{#pageTitle#}</title>
|
<title>{#pageTitle#}</title>
|
||||||
<body bgcolor="{#bodyBgColor#}">
|
<body bgcolor="{#bodyBgColor#}">
|
||||||
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
|
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
|
||||||
<tr bgcolor="{#rowBgColor#}">
|
<tr bgcolor="{#rowBgColor#}">
|
||||||
<td>First</td>
|
<td>First</td>
|
||||||
<td>Last</td>
|
<td>Last</td>
|
||||||
<td>Address</td>
|
<td>Address</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
]]>
|
||||||
index.tpl: (alternate syntax)
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
index.tpl: (alternate syntax)
|
||||||
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
{config_load file="foo.conf"}
|
{config_load file="foo.conf"}
|
||||||
<html>
|
<html>
|
||||||
<title>{$smarty.config.pageTitle}</title>
|
<title>{$smarty.config.pageTitle}</title>
|
||||||
<body bgcolor="{$smarty.config.bodyBgColor}">
|
<body bgcolor="{$smarty.config.bodyBgColor}">
|
||||||
<table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
|
<table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
|
||||||
<tr bgcolor="{$smarty.config.rowBgColor}">
|
<tr bgcolor="{$smarty.config.rowBgColor}">
|
||||||
<td>First</td>
|
<td>First</td>
|
||||||
<td>Last</td>
|
<td>Last</td>
|
||||||
<td>Address</td>
|
<td>Address</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
OUTPUT: (same for both examples)
|
<para>
|
||||||
|
this will output for both examples:
|
||||||
<html>
|
</para>
|
||||||
<title>This is mine</title>
|
<screen>
|
||||||
<body bgcolor="#eeeeee">
|
<![CDATA[
|
||||||
<table border="3" bgcolor="#bbbbbb">
|
<html>
|
||||||
<tr bgcolor="#cccccc">
|
<title>This is mine</title>
|
||||||
<td>First</td>
|
<body bgcolor="#eeeeee">
|
||||||
<td>Last</td>
|
<table border="3" bgcolor="#bbbbbb">
|
||||||
<td>Address</td>
|
<tr bgcolor="#cccccc">
|
||||||
</tr>
|
<td>First</td>
|
||||||
</table>
|
<td>Last</td>
|
||||||
</body>
|
<td>Address</td>
|
||||||
</html></programlisting>
|
</tr>
|
||||||
</example>
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
|
</example>
|
||||||
<para>
|
<para>
|
||||||
Config file variables cannot be used until
|
Config file variables cannot be used until
|
||||||
after they are loaded in from a config file. This procedure is
|
after they are loaded in from a config file. This procedure is
|
||||||
explained later in this document under
|
explained later in this document under <command>config_load</command>.
|
||||||
<command>config_load</command>.
|
|
||||||
</para>
|
</para>
|
||||||
</sect1>
|
</sect1>
|
||||||
|
|
||||||
<sect1 id="language.variables.smarty">
|
<sect1 id="language.variables.smarty">
|
||||||
<title>{$smarty} reserved variable</title>
|
<title>{$smarty} reserved variable</title>
|
||||||
<para>
|
<para>
|
||||||
The reserved {$smarty} variable can be used to access several
|
The reserved {$smarty} variable can be used to access several
|
||||||
special template variables. The full list of them follows.
|
special template variables. The full list of them follows.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<sect2 id="language.variables.smarty.request">
|
<sect2 id="language.variables.smarty.request">
|
||||||
<title>Request variables</title>
|
<title>Request variables</title>
|
||||||
<para>
|
<para>
|
||||||
The request variables such as get, post, cookies, server,
|
The request variables such as get, post, cookies, server,
|
||||||
environment, and session variables can be accessed as demonstrated
|
environment, and session variables can be accessed as demonstrated
|
||||||
in the examples below:
|
in the examples below:
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
|
<title>displaying request variables</title>
|
||||||
<title>displaying request variables</title>
|
<programlisting>
|
||||||
<programlisting>
|
<![CDATA[
|
||||||
{* display value of page from URL (GET) http://www.domain.com/index.php?page=foo *}
|
{* display value of page from URL (GET) http://www.domain.com/index.php?page=foo *}
|
||||||
{$smarty.get.page}
|
{$smarty.get.page}
|
||||||
|
|
||||||
@@ -249,89 +303,97 @@ OUTPUT: (same for both examples)
|
|||||||
{$smarty.session.id}
|
{$smarty.session.id}
|
||||||
|
|
||||||
{* display the variable "username" from merged get/post/cookies/server/env *}
|
{* display the variable "username" from merged get/post/cookies/server/env *}
|
||||||
{$smarty.request.username}</programlisting>
|
{$smarty.request.username}
|
||||||
</example>
|
]]>
|
||||||
<para>
|
</programlisting>
|
||||||
Note: For historical reasons {$SCRIPT_NAME} can be accessed
|
</example>
|
||||||
directly though {$smarty.server.SCRIPT_NAME} is the
|
<note>
|
||||||
proposed way to access this value.
|
<para>
|
||||||
</para>
|
For historical reasons {$SCRIPT_NAME} can be accessed
|
||||||
|
directly though {$smarty.server.SCRIPT_NAME} is the
|
||||||
|
proposed way to access this value.
|
||||||
|
</para>
|
||||||
|
</note>
|
||||||
|
</sect2>
|
||||||
|
|
||||||
</sect2>
|
<sect2 id="language.variables.smarty.now">
|
||||||
|
|
||||||
<sect2 id="language.variables.smarty.now">
|
|
||||||
<title>{$smarty.now}</title>
|
<title>{$smarty.now}</title>
|
||||||
<para>
|
<para>
|
||||||
The current timestamp can be accessed with {$smarty.now}. The
|
The current timestamp can be accessed with {$smarty.now}. The
|
||||||
number reflects the number of seconds passed since the so-called
|
number reflects the number of seconds passed since the so-called
|
||||||
Epoch (January 1, 1970) and can be passed directly to
|
Epoch (January 1, 1970) and can be passed directly to
|
||||||
date_format modifier for display purposes.
|
date_format modifier for display purposes.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
|
<title>using {$smarty.now}</title>
|
||||||
<title>using {$smarty.now}</title>
|
<programlisting>
|
||||||
<programlisting>
|
<![CDATA[
|
||||||
{* use the date_format modifier to show current date and time *}
|
{* use the date_format modifier to show current date and time *}
|
||||||
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}</programlisting>
|
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
|
||||||
</example>
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
<sect2 id="language.variables.smarty.const">
|
<sect2 id="language.variables.smarty.const">
|
||||||
<title>{$smarty.const}</title>
|
<title>{$smarty.const}</title>
|
||||||
<para>
|
<para>
|
||||||
You can access PHP constant values directly.
|
You can access PHP constant values directly.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
|
<title>using {$smarty.const}</title>
|
||||||
<title>using {$smarty.const}</title>
|
<programlisting>
|
||||||
<programlisting>
|
<![CDATA[
|
||||||
{$smarty.const._MY_CONST_VAL}</programlisting>
|
{$smarty.const._MY_CONST_VAL}
|
||||||
</example>
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="language.variables.smarty.capture">
|
<sect2 id="language.variables.smarty.capture">
|
||||||
<title>{$smarty.capture}</title>
|
<title>{$smarty.capture}</title>
|
||||||
<para>
|
<para>
|
||||||
The output captured via {capture}..{/capture} construct can be
|
The output captured via {capture}..{/capture} construct can be
|
||||||
accessed using {$smarty} variable. See section on
|
accessed using {$smarty} variable. See section on
|
||||||
<link linkend="language.function.capture">capture</link> for an example.
|
<link linkend="language.function.capture">capture</link> for an example.
|
||||||
</para>
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="language.variables.smarty.config">
|
<sect2 id="language.variables.smarty.config">
|
||||||
<title>{$smarty.config}</title>
|
<title>{$smarty.config}</title>
|
||||||
<para>
|
<para>
|
||||||
{$smarty} variable can be used to refer to loaded config variables.
|
{$smarty} variable can be used to refer to loaded config variables.
|
||||||
{$smarty.config.foo} is a synonym for {#foo#}. See the section on
|
{$smarty.config.foo} is a synonym for {#foo#}. See the section on
|
||||||
<link linkend="language.function.config.load">config_load</link> for an example.
|
<link linkend="language.function.config.load">config_load</link> for an example.
|
||||||
</para>
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="language.variables.smarty.loops">
|
<sect2 id="language.variables.smarty.loops">
|
||||||
<title>{$smarty.section}, {$smarty.foreach}</title>
|
<title>{$smarty.section}, {$smarty.foreach}</title>
|
||||||
<para>
|
<para>
|
||||||
{$smarty} variable can be used to refer to 'section' and
|
{$smarty} variable can be used to refer to 'section' and
|
||||||
'foreach' loop properties. See docs for
|
'foreach' loop properties. See docs for
|
||||||
<link linkend="language.function.section">section</link> and
|
<link linkend="language.function.section">section</link> and
|
||||||
<link linkend="language.function.foreach">foreach</link>.
|
<link linkend="language.function.foreach">foreach</link>.
|
||||||
</para>
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="language.variables.smarty.template">
|
<sect2 id="language.variables.smarty.template">
|
||||||
<title>{$smarty.template}</title>
|
<title>{$smarty.template}</title>
|
||||||
<para>
|
<para>
|
||||||
This variable contains the name of the current template being
|
This variable contains the name of the current template being
|
||||||
processed.
|
processed.
|
||||||
</para>
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
<sect2 id="language.variables.smarty.version">
|
<sect2 id="language.variables.smarty.version">
|
||||||
<title>{$smarty.version}</title>
|
<title>{$smarty.version}</title>
|
||||||
<para>
|
<para>
|
||||||
This variable contains the version of Smarty the template was compiled with.
|
This variable contains the version of Smarty the template was compiled with.
|
||||||
</para>
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
</sect1>
|
</sect1>
|
||||||
</chapter>
|
</chapter>
|
||||||
|
|
||||||
<!-- Keep this comment at the end of the file
|
<!-- Keep this comment at the end of the file
|
||||||
Local variables:
|
Local variables:
|
||||||
mode: sgml
|
mode: sgml
|
||||||
@@ -351,4 +413,4 @@ End:
|
|||||||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||||||
vim: et tw=78 syn=sgml
|
vim: et tw=78 syn=sgml
|
||||||
vi: ts=1 sw=1
|
vi: ts=1 sw=1
|
||||||
-->
|
-->
|
||||||
|
Reference in New Issue
Block a user