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>
|
||||
<title>Comments</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* Smarty *}
|
||||
|
||||
{* include the header file here *}
|
||||
@@ -36,9 +37,11 @@
|
||||
{include file=#includeFile#}
|
||||
|
||||
{* display dropdown lists *}
|
||||
<SELECT name=company>
|
||||
<select name="company">
|
||||
{html_options values=$vals selected=$selected output=$output}
|
||||
</SELECT></programlisting>
|
||||
</select>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
|
||||
@@ -99,6 +102,7 @@
|
||||
<example>
|
||||
<title>function attribute syntax</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{include file="header.tpl"}
|
||||
|
||||
{include file=$includeFile}
|
||||
@@ -107,10 +111,12 @@
|
||||
|
||||
{html_select_date display_days=yes}
|
||||
|
||||
<SELECT name=company>
|
||||
<select name="company">
|
||||
{html_options values=$vals selected=$selected output=$output}
|
||||
</SELECT></programlisting>
|
||||
</example>
|
||||
</select>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="language.syntax.quotes">
|
||||
<title>Embedding Vars in Double Quotes</title>
|
||||
@@ -123,18 +129,21 @@
|
||||
<example>
|
||||
<title>embedded quotes syntax</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
SYNTAX EXAMPLES:
|
||||
{func var="test $foo test"} <-- sees $foo
|
||||
{func var="test $foo_bar test"} <-- sees $foo_bar
|
||||
{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 (not $foo.bar)
|
||||
{func var="test `$foo.bar` test"} <-- sees $foo.bar
|
||||
{func var="test $foo test"} <-- sees $foo
|
||||
{func var="test $foo_bar test"} <-- sees $foo_bar
|
||||
{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 (not $foo.bar)
|
||||
{func var="test `$foo.bar` test"} <-- sees $foo.bar
|
||||
|
||||
PRACTICAL EXAMPLES:
|
||||
{include file="subdir/$tpl_name.tpl"} <-- will replace $tpl_name with value
|
||||
{cycle values="one,two,`$smarty.config.myval`"} <-- must have backticks</programlisting>
|
||||
</example>
|
||||
{include file="subdir/$tpl_name.tpl"} <-- will replace $tpl_name with value
|
||||
{cycle values="one,two,`$smarty.config.myval`"} <-- must have backticks
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="language.math">
|
||||
<title>Math</title>
|
||||
@@ -144,20 +153,23 @@ PRACTICAL EXAMPLES:
|
||||
<example>
|
||||
<title>math examples</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{$foo+1}
|
||||
|
||||
{$foo*$bar}
|
||||
|
||||
{* 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)}
|
||||
|
||||
{$foo|truncate:"`$fooTruncCount/$barTruncFactor-1`"}
|
||||
|
||||
{assign var="foo" value="`$foo+$bar`"}</programlisting>
|
||||
</example>
|
||||
{assign var="foo" value="`$foo+$bar`"}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="language.escaping">
|
||||
@@ -174,39 +186,46 @@ PRACTICAL EXAMPLES:
|
||||
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>
|
||||
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>
|
||||
It is often convenient to simply change Smarty's <link linkend="variable.left.delimiter">$left_delimiter</link> and
|
||||
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>
|
||||
<example>
|
||||
<title>changing delimiters example</title>
|
||||
<programlisting>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->left_delimiter = '<!--{';
|
||||
$smarty->right_delimiter = '}-->';
|
||||
$smarty->left_delimiter = '<!--{';
|
||||
$smarty->right_delimiter = '}-->';
|
||||
$smarty->assign('foo', 'bar');
|
||||
$smarty->display('example.tpl');
|
||||
|
||||
?>
|
||||
|
||||
--- example.tpl
|
||||
<script language="javascript">
|
||||
var foo = <!--{$foo}-->;
|
||||
<script language="javascript">
|
||||
var foo = <!--{$foo}-->;
|
||||
function dosomething() {
|
||||
alert("foo is " + foo);
|
||||
}
|
||||
dosomething();
|
||||
</script>
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
</script>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
</chapter>
|
||||
</chapter>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
|
@@ -13,11 +13,14 @@
|
||||
etc. To print a variable, simply enclose it in the delimiters so that it
|
||||
is the only thing contained between them. Examples:
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{$Name}
|
||||
|
||||
{$Contacts[row].Phone}
|
||||
|
||||
<body bgcolor="{#bgcolor#}"></programlisting>
|
||||
<body bgcolor="{#bgcolor#}">
|
||||
]]>
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<sect1 id="language.assigned.variables">
|
||||
@@ -31,17 +34,24 @@
|
||||
<example>
|
||||
|
||||
<title>assigned variables</title>
|
||||
<programlisting>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
Hello {$firstname}, glad to see you could make it.
|
||||
<p>
|
||||
<br />
|
||||
Your last login was on {$lastLoginDate}.
|
||||
|
||||
OUTPUT:
|
||||
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
This will output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Hello Doug, glad to see you could make it.
|
||||
<p>
|
||||
Your last login was on January 11th, 2001.</programlisting>
|
||||
</example>
|
||||
<br />
|
||||
Your last login was on January 11th, 2001.
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<sect2 id="language.variables.assoc.arrays">
|
||||
<title>Associative arrays</title>
|
||||
@@ -50,34 +60,45 @@ Your last login was on January 11th, 2001.</programlisting>
|
||||
assigned from PHP by specifying the key after the '.' (period)
|
||||
symbol.
|
||||
</para>
|
||||
<example>
|
||||
<title>accessing associative array variables</title>
|
||||
<programlisting>
|
||||
index.php:
|
||||
|
||||
<example>
|
||||
<title>accessing associative array variables</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('Contacts',
|
||||
$smarty->assign('Contacts',
|
||||
array('fax' => '555-222-9876',
|
||||
'email' => 'zaphod@slartibartfast.com',
|
||||
'phone' => array('home' => '555-444-3333',
|
||||
'cell' => '555-111-1234')));
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
index.tpl:
|
||||
|
||||
{$Contacts.fax}<br>
|
||||
{$Contacts.email}<br>
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
where the content of index.tpl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{$Contacts.fax}<br />
|
||||
{$Contacts.email}<br />
|
||||
{* you can print arrays of arrays as well *}
|
||||
{$Contacts.phone.home}<br>
|
||||
{$Contacts.phone.cell}<br>
|
||||
|
||||
OUTPUT:
|
||||
|
||||
555-222-9876<br>
|
||||
zaphod@slartibartfast.com<br>
|
||||
555-444-3333<br>
|
||||
555-111-1234<br></programlisting>
|
||||
</example>
|
||||
{$Contacts.phone.home}<br />
|
||||
{$Contacts.phone.cell}<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.array.indexes">
|
||||
<title>Array indexes</title>
|
||||
@@ -85,34 +106,47 @@ zaphod@slartibartfast.com<br>
|
||||
You can reference arrays by their index, much like native PHP
|
||||
syntax.
|
||||
</para>
|
||||
<example>
|
||||
<title>accessing arrays by index</title>
|
||||
<programlisting>
|
||||
index.php:
|
||||
<example>
|
||||
<title>accessing arrays by index</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$smarty = new Smarty;
|
||||
$smarty->assign('Contacts',
|
||||
$smarty->assign('Contacts',
|
||||
array('555-222-9876',
|
||||
'zaphod@slartibartfast.com',
|
||||
array('555-444-3333',
|
||||
'555-111-1234')));
|
||||
$smarty->display('index.tpl');
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
index.tpl:
|
||||
|
||||
{$Contacts[0]}<br>
|
||||
{$Contacts[1]}<br>
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
where index.tpl is:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{$Contacts[0]}<br />
|
||||
{$Contacts[1]}<br />
|
||||
{* you can print arrays of arrays as well *}
|
||||
{$Contacts[2][0]}<br>
|
||||
{$Contacts[2][1]}<br>
|
||||
|
||||
OUTPUT:
|
||||
|
||||
555-222-9876<br>
|
||||
zaphod@slartibartfast.com<br>
|
||||
555-444-3333<br>
|
||||
555-111-1234<br></programlisting>
|
||||
</example>
|
||||
{$Contacts[2][0]}<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>
|
||||
@@ -120,17 +154,24 @@ zaphod@slartibartfast.com<br>
|
||||
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>
|
||||
<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>
|
||||
|
||||
@@ -144,71 +185,84 @@ email: zaphod@slartibartfast.com<br></programlisting>
|
||||
The second syntax is useful for embedding into quoted attribute
|
||||
values.
|
||||
</para>
|
||||
<example>
|
||||
|
||||
<title>config variables</title>
|
||||
<programlisting>
|
||||
foo.conf:
|
||||
|
||||
<example>
|
||||
<title>config variables</title>
|
||||
<para>
|
||||
foo.conf:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
pageTitle = "This is mine"
|
||||
bodyBgColor = "#eeeeee"
|
||||
tableBorderSize = "3"
|
||||
tableBgColor = "#bbbbbb"
|
||||
rowBgColor = "#cccccc"
|
||||
|
||||
index.tpl:
|
||||
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
index.tpl:
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{config_load file="foo.conf"}
|
||||
<html>
|
||||
<title>{#pageTitle#}</title>
|
||||
<body bgcolor="{#bodyBgColor#}">
|
||||
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
|
||||
<tr bgcolor="{#rowBgColor#}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
index.tpl: (alternate syntax)
|
||||
|
||||
<html>
|
||||
<title>{#pageTitle#}</title>
|
||||
<body bgcolor="{#bodyBgColor#}">
|
||||
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
|
||||
<tr bgcolor="{#rowBgColor#}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
index.tpl: (alternate syntax)
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{config_load file="foo.conf"}
|
||||
<html>
|
||||
<title>{$smarty.config.pageTitle}</title>
|
||||
<body bgcolor="{$smarty.config.bodyBgColor}">
|
||||
<table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
|
||||
<tr bgcolor="{$smarty.config.rowBgColor}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
OUTPUT: (same for both examples)
|
||||
|
||||
<html>
|
||||
<title>This is mine</title>
|
||||
<body bgcolor="#eeeeee">
|
||||
<table border="3" bgcolor="#bbbbbb">
|
||||
<tr bgcolor="#cccccc">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html></programlisting>
|
||||
</example>
|
||||
<html>
|
||||
<title>{$smarty.config.pageTitle}</title>
|
||||
<body bgcolor="{$smarty.config.bodyBgColor}">
|
||||
<table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
|
||||
<tr bgcolor="{$smarty.config.rowBgColor}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
this will output for both examples:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
<html>
|
||||
<title>This is mine</title>
|
||||
<body bgcolor="#eeeeee">
|
||||
<table border="3" bgcolor="#bbbbbb">
|
||||
<tr bgcolor="#cccccc">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
<para>
|
||||
Config file variables cannot be used until
|
||||
after they are loaded in from a config file. This procedure is
|
||||
explained later in this document under
|
||||
<command>config_load</command>.
|
||||
explained later in this document under <command>config_load</command>.
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
@@ -227,9 +281,9 @@ OUTPUT: (same for both examples)
|
||||
in the examples below:
|
||||
</para>
|
||||
<example>
|
||||
|
||||
<title>displaying request variables</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* display value of page from URL (GET) http://www.domain.com/index.php?page=foo *}
|
||||
{$smarty.get.page}
|
||||
|
||||
@@ -249,14 +303,17 @@ OUTPUT: (same for both examples)
|
||||
{$smarty.session.id}
|
||||
|
||||
{* display the variable "username" from merged get/post/cookies/server/env *}
|
||||
{$smarty.request.username}</programlisting>
|
||||
</example>
|
||||
{$smarty.request.username}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<note>
|
||||
<para>
|
||||
Note: For historical reasons {$SCRIPT_NAME} can be accessed
|
||||
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 id="language.variables.smarty.now">
|
||||
@@ -267,25 +324,29 @@ OUTPUT: (same for both examples)
|
||||
Epoch (January 1, 1970) and can be passed directly to
|
||||
date_format modifier for display purposes.
|
||||
</para>
|
||||
<example>
|
||||
|
||||
<title>using {$smarty.now}</title>
|
||||
<programlisting>
|
||||
<example>
|
||||
<title>using {$smarty.now}</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* use the date_format modifier to show current date and time *}
|
||||
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}</programlisting>
|
||||
</example>
|
||||
{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="language.variables.smarty.const">
|
||||
<title>{$smarty.const}</title>
|
||||
<para>
|
||||
You can access PHP constant values directly.
|
||||
</para>
|
||||
<example>
|
||||
|
||||
<title>using {$smarty.const}</title>
|
||||
<programlisting>
|
||||
{$smarty.const._MY_CONST_VAL}</programlisting>
|
||||
</example>
|
||||
<example>
|
||||
<title>using {$smarty.const}</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{$smarty.const._MY_CONST_VAL}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="language.variables.smarty.capture">
|
||||
@@ -332,6 +393,7 @@ OUTPUT: (same for both examples)
|
||||
|
||||
</sect1>
|
||||
</chapter>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
|
Reference in New Issue
Block a user