mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
update documenatation, template examples
This commit is contained in:
7
NEWS
7
NEWS
@@ -1,12 +1,13 @@
|
||||
- numerous documentation updates. (Monte)
|
||||
- added ENT_QUOTES to escapement of html (Monte, Sam Beckwith)
|
||||
- implemented access to request variables via auto-assigned $smarty
|
||||
template variable. (Andrei)
|
||||
- fixed a bug with parsing function arguments inside {if} tags if a comma
|
||||
was present. (Andrei)
|
||||
- updated debug console with config file vars. (Monte)
|
||||
- numerous documentation updates. (Monte)
|
||||
- added SMARTY_DIR constant which indicating location of Smarty files.
|
||||
- added SMARTY_DIR constant as an alternative to relying on include_path
|
||||
(Monte)
|
||||
- added popup_init and popup functions. (Monte)
|
||||
- added popup_init and popup functions, (requires overlib.js) (Monte)
|
||||
- updated debug console with config file vars. (Monte)
|
||||
- added debugging url control. (Monte)
|
||||
- added 'quotes' type to escape modifier. (Monte, Mike Krus)
|
||||
|
@@ -83,7 +83,7 @@ function smarty_mod_escape($string, $esc_type = 'html')
|
||||
{
|
||||
switch ($esc_type) {
|
||||
case 'html':
|
||||
return htmlspecialchars($string);
|
||||
return htmlspecialchars($string, ENT_QUOTES);
|
||||
|
||||
case 'url':
|
||||
return urlencode($string);
|
||||
|
@@ -514,7 +514,6 @@ class Smarty_Compiler extends Smarty {
|
||||
)/x', $tag_args, $match);
|
||||
$tokens = $match[0];
|
||||
|
||||
var_dump($tokens);
|
||||
$this->_parse_vars_props($tokens);
|
||||
|
||||
$is_arg_stack = array();
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
{tooltip_init}
|
||||
{tooltip_element id="help" width="200" text="This is an example of a tooltip. Tooltips are handy for context sensitive information."}
|
||||
{popup_init}
|
||||
</HEAD>
|
||||
<BODY bgcolor="#ffffff">
|
||||
<TITLE>{$title} - {$Name}</TITLE>
|
||||
|
@@ -9,14 +9,21 @@
|
||||
Title: {#title#|capitalize}
|
||||
{if #bold#}</b>{/if}
|
||||
|
||||
Tooltip example: Move your mouse over the <A HREF="" {tooltip id="help"} onclick="return false;">Help</A> link to see a tooltip pop-up.
|
||||
Tooltip example: Move your mouse over the <A HREF="" {popup sticky=true caption="Smarty pop-up text" delay=400 text="This is an example of a tooltip. Tooltips are handy for context sensitive information, and extremely easy to add to your templates with Smarty and the integration of <a href='http://www.bosrup.com/web/overlib/'>overLIB</a> by Erik Bosrup"} onclick="return false;">Help</A> link to see an example of a tooltip using Smarty's popup function.
|
||||
|
||||
the value of $SCRIPT_NAME is {$SCRIPT_NAME}
|
||||
The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}
|
||||
|
||||
{* A simple variable test. print $Name in uppercase *}
|
||||
hello, my name is {$Name}
|
||||
Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME}
|
||||
|
||||
The value of {ldelim}$Name{rdelim} is <b>{$Name}</b>
|
||||
|
||||
variable modifier example of {ldelim}$Name|upper{rdelim}
|
||||
|
||||
<b>{$Name|upper}</b>
|
||||
|
||||
|
||||
An example of a section loop:
|
||||
|
||||
My interests are:
|
||||
{section name=outer loop=$FirstName}
|
||||
{if %outer.index% is odd by 2}
|
||||
{%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]}
|
||||
@@ -27,7 +34,8 @@ My interests are:
|
||||
none
|
||||
{/section}
|
||||
|
||||
testing section looped key values<br>
|
||||
An example of section looped key values:
|
||||
|
||||
{section name=sec1 loop=$contacts}
|
||||
phone: {$contacts[sec1].phone}<br>
|
||||
fax: {$contacts[sec1].fax}<br>
|
||||
|
193
docs.sgml
193
docs.sgml
@@ -249,6 +249,17 @@ chmod 700 cache
|
||||
used to locate the files. If defined, the path must end with a
|
||||
slash.
|
||||
</para>
|
||||
<example>
|
||||
<title>SMARTY_DIR</title>
|
||||
<programlisting>
|
||||
|
||||
// set path to Smarty directory
|
||||
define("SMARTY_DIR","/usr/local/lib/php/Smarty/");
|
||||
|
||||
require_once(SMARTY_DIR."Smarty.class.php");
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
</sect1>
|
||||
<sect1>
|
||||
@@ -1400,12 +1411,6 @@ $smarty->display("index.tpl");
|
||||
between the tags, and displays the appropriate output in place of them.
|
||||
</para>
|
||||
<sect2>
|
||||
<title>Variables</title>
|
||||
<para>
|
||||
There are three basic types of variables in Smarty, each with their
|
||||
own unique syntax.
|
||||
</para>
|
||||
<sect3>
|
||||
<title>Variables assigned from PHP</title>
|
||||
<para>
|
||||
Variables that are assigned from PHP are referenced by preceding
|
||||
@@ -1428,9 +1433,8 @@ Hello Doug, glad to see you could make it.
|
||||
Your last login was on January 11th, 2001.
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>Associative arrays</title>
|
||||
<para>
|
||||
You can also reference associative array variables that are
|
||||
@@ -1458,9 +1462,8 @@ zaphod@slartibartfast.com<br>
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>Objects</title>
|
||||
<para>
|
||||
Properties of objects assigned from PHP can be referenced
|
||||
@@ -1480,9 +1483,9 @@ email: zaphod@slartibartfast.com<br>
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
</sect2>
|
||||
|
||||
<sect3>
|
||||
<sect2>
|
||||
<title>Variables passed from config files</title>
|
||||
<para>
|
||||
Variables that are passed in from config files are displayed by enclosing
|
||||
@@ -1499,11 +1502,11 @@ email: zaphod@slartibartfast.com<br>
|
||||
<title>{#pageTitle#}</title>
|
||||
<body bgcolor="{#bodyBgColor#}">
|
||||
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
|
||||
<tr bgcolor="{#rowBgColor#}">
|
||||
<tr bgcolor="{#rowBgColor#}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1515,8 +1518,8 @@ email: zaphod@slartibartfast.com<br>
|
||||
explained later in this document under
|
||||
<link linkend="builtin.functions.configload">config_load</link>.
|
||||
</para>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>Variables internal to template</title>
|
||||
<para>
|
||||
Variables that are internal to the templates are displayed by enclosing
|
||||
@@ -1525,7 +1528,45 @@ email: zaphod@slartibartfast.com<br>
|
||||
variables used in Smarty, which can be found later in this document under
|
||||
<link linkend="builtin.functions.section">section</link>.
|
||||
</para>
|
||||
</sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>Request Variables</title>
|
||||
<para>
|
||||
You can access request variables in Smarty via the special variable
|
||||
{$smarty}. You can access get, post, cookies, server, env and
|
||||
session variables with the syntax in the following examples.
|
||||
</para>
|
||||
<para>
|
||||
Request variable access was added to Smarty 1.4.4.
|
||||
</para>
|
||||
<example>
|
||||
|
||||
<title>displaying request variables</title>
|
||||
<programlisting>
|
||||
|
||||
{* display the variable "page" given in the URL, or from a form using the GET method *}
|
||||
{$smarty.get.page}
|
||||
|
||||
{* display the variable "page" from a form using the POST method *}
|
||||
{$smarty.post.page}
|
||||
|
||||
{* display the value of the cookie "username" *}
|
||||
{$smarty.cookies.username}
|
||||
|
||||
{* display the server variable "SERVER_NAME" *}
|
||||
{$smarty.server.SERVER_NAME}
|
||||
|
||||
{* display the system environment variable "PATH" *}
|
||||
{$smarty.env.PATH}
|
||||
|
||||
{* display the php session variable "id" *}
|
||||
{$smarty.session.id}
|
||||
|
||||
{* display the variable "username" from merged get/post/cookies/server/env *}
|
||||
{$smarty.request.username}
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>Functions</title>
|
||||
@@ -2402,7 +2443,8 @@ e-mail: jane@mydomain.com<p>
|
||||
These are indicated by percent signs around the variable name, like so:
|
||||
%sectionname.varname%
|
||||
</para>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>index</title>
|
||||
<para>
|
||||
index is used to display the current loop index, starting with zero
|
||||
@@ -2418,7 +2460,7 @@ e-mail: jane@mydomain.com<p>
|
||||
<title>section property index</title>
|
||||
<programlisting>
|
||||
{section name=customer loop=$custid}
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{/section}
|
||||
|
||||
|
||||
@@ -2430,8 +2472,8 @@ OUTPUT:
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>index_prev</title>
|
||||
<para>
|
||||
index_prev is used to display the previous loop index.
|
||||
@@ -2441,11 +2483,11 @@ OUTPUT:
|
||||
<title>section property index_prev</title>
|
||||
<programlisting>
|
||||
{section name=customer loop=$custid}
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
|
||||
{if $custid[customer.index_prev] ne $custid[customer.index]}
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
|
||||
{if $custid[customer.index_prev] ne $custid[customer.index]}
|
||||
The customer id changed<br>
|
||||
{/if}
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
@@ -2460,8 +2502,8 @@ OUTPUT:
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>index_next</title>
|
||||
<para>
|
||||
index_next is used to display the next loop index. On the last
|
||||
@@ -2472,11 +2514,11 @@ OUTPUT:
|
||||
<title>section property index_next</title>
|
||||
<programlisting>
|
||||
{section name=customer loop=$custid}
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
|
||||
{if $custid[customer.index_next] ne $custid[customer.index]}
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
|
||||
{if $custid[customer.index_next] ne $custid[customer.index]}
|
||||
The customer id will change<br>
|
||||
{/if}
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
@@ -2491,8 +2533,8 @@ OUTPUT:
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>iteration</title>
|
||||
<para>
|
||||
iteration is used to display the current loop iteration.
|
||||
@@ -2508,12 +2550,12 @@ OUTPUT:
|
||||
<title>section property iteration</title>
|
||||
<programlisting>
|
||||
{section name=customer loop=$custid start=5 step=2}
|
||||
current loop iteration: {%customer.iteration%}<br>
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
|
||||
{if $custid[customer.index_next] ne $custid[customer.index]}
|
||||
current loop iteration: {%customer.iteration%}<br>
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
|
||||
{if $custid[customer.index_next] ne $custid[customer.index]}
|
||||
The customer id will change<br>
|
||||
{/if}
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
@@ -2531,8 +2573,8 @@ current loop iteration: 3
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>first</title>
|
||||
<para>
|
||||
first is set to true if the current section iteration is the first
|
||||
@@ -2542,31 +2584,31 @@ current loop iteration: 3
|
||||
<title>section property first</title>
|
||||
<programlisting>
|
||||
{section name=customer loop=$custid}
|
||||
{if %customer.first%}
|
||||
{if %customer.first%}
|
||||
<table>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<tr><td>{%customer.index%} id:
|
||||
<tr><td>{%customer.index%} id:
|
||||
{$custid[customer]}</td></tr>
|
||||
|
||||
{if %customer.last%}
|
||||
{if %customer.last%}
|
||||
</table>
|
||||
{/if}
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
<table>
|
||||
<tr><td>0 id: 1000</td></tr>
|
||||
<tr><td>1 id: 1001</td></tr>
|
||||
<tr><td>2 id: 1002</td></tr>
|
||||
<tr><td>0 id: 1000</td></tr>
|
||||
<tr><td>1 id: 1001</td></tr>
|
||||
<tr><td>2 id: 1002</td></tr>
|
||||
</table>
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>last</title>
|
||||
<para>
|
||||
last is set to true if the current section iteration is the last
|
||||
@@ -2576,31 +2618,31 @@ OUTPUT:
|
||||
<title>section property last</title>
|
||||
<programlisting>
|
||||
{section name=customer loop=$custid}
|
||||
{if %customer.first%}
|
||||
{if %customer.first%}
|
||||
<table>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<tr><td>{%customer.index%} id:
|
||||
<tr><td>{%customer.index%} id:
|
||||
{$custid[customer]}</td></tr>
|
||||
|
||||
{if %customer.last%}
|
||||
{if %customer.last%}
|
||||
</table>
|
||||
{/if}
|
||||
{/if}
|
||||
{/section}
|
||||
|
||||
|
||||
OUTPUT:
|
||||
|
||||
<table>
|
||||
<tr><td>0 id: 1000</td></tr>
|
||||
<tr><td>1 id: 1001</td></tr>
|
||||
<tr><td>2 id: 1002</td></tr>
|
||||
<tr><td>0 id: 1000</td></tr>
|
||||
<tr><td>1 id: 1001</td></tr>
|
||||
<tr><td>2 id: 1002</td></tr>
|
||||
</table>
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>rownum</title>
|
||||
<para>
|
||||
rownum is used to display the current loop iteration,
|
||||
@@ -2610,7 +2652,7 @@ OUTPUT:
|
||||
<title>section property rownum</title>
|
||||
<programlisting>
|
||||
{section name=customer loop=$custid}
|
||||
{%customer.rownum%} id: {$custid[customer]}<br>
|
||||
{%customer.rownum%} id: {$custid[customer]}<br>
|
||||
{/section}
|
||||
|
||||
|
||||
@@ -2622,8 +2664,8 @@ OUTPUT:
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>loop</title>
|
||||
<para>
|
||||
loop is used to display the last index number that this section
|
||||
@@ -2633,7 +2675,7 @@ OUTPUT:
|
||||
<title>section property index</title>
|
||||
<programlisting>
|
||||
{section name=customer loop=$custid}
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{/section}
|
||||
|
||||
There were {%customer.loop%} customers shown above.
|
||||
@@ -2648,8 +2690,8 @@ There were 3 customers shown above.
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>show</title>
|
||||
<para>
|
||||
<emphasis>show</emphasis> is used as a parameter to section.
|
||||
@@ -2661,15 +2703,15 @@ There were 3 customers shown above.
|
||||
<title>section attribute show</title>
|
||||
<programlisting>
|
||||
{* $show_customer_info may have been passed from the PHP
|
||||
application, to regulate whether or not this section shows *}
|
||||
application, to regulate whether or not this section shows *}
|
||||
{section name=customer loop=$custid show=$show_customer_info}
|
||||
{%customer.rownum%} id: {$custid[customer]}<br>
|
||||
{%customer.rownum%} id: {$custid[customer]}<br>
|
||||
{/section}
|
||||
|
||||
{if %customer.show%}
|
||||
the section was shown.
|
||||
the section was shown.
|
||||
{else}
|
||||
the section was not shown.
|
||||
the section was not shown.
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -2683,8 +2725,8 @@ the section was shown.
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
<sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>total</title>
|
||||
<para>
|
||||
total is used to display the number of iterations that this section
|
||||
@@ -2697,7 +2739,7 @@ the section was shown.
|
||||
<title>section property total</title>
|
||||
<programlisting>
|
||||
{section name=customer loop=$custid step=2}
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{%customer.index%} id: {$custid[customer]}<br>
|
||||
{/section}
|
||||
|
||||
There were {%customer.total%} customers shown above.
|
||||
@@ -2712,7 +2754,6 @@ There were 3 customers shown above.
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect3>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>strip</title>
|
||||
|
@@ -514,7 +514,6 @@ class Smarty_Compiler extends Smarty {
|
||||
)/x', $tag_args, $match);
|
||||
$tokens = $match[0];
|
||||
|
||||
var_dump($tokens);
|
||||
$this->_parse_vars_props($tokens);
|
||||
|
||||
$is_arg_stack = array();
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
{tooltip_init}
|
||||
{tooltip_element id="help" width="200" text="This is an example of a tooltip. Tooltips are handy for context sensitive information."}
|
||||
{popup_init}
|
||||
</HEAD>
|
||||
<BODY bgcolor="#ffffff">
|
||||
<TITLE>{$title} - {$Name}</TITLE>
|
||||
|
@@ -9,14 +9,21 @@
|
||||
Title: {#title#|capitalize}
|
||||
{if #bold#}</b>{/if}
|
||||
|
||||
Tooltip example: Move your mouse over the <A HREF="" {tooltip id="help"} onclick="return false;">Help</A> link to see a tooltip pop-up.
|
||||
Tooltip example: Move your mouse over the <A HREF="" {popup sticky=true caption="Smarty pop-up text" delay=400 text="This is an example of a tooltip. Tooltips are handy for context sensitive information, and extremely easy to add to your templates with Smarty and the integration of <a href='http://www.bosrup.com/web/overlib/'>overLIB</a> by Erik Bosrup"} onclick="return false;">Help</A> link to see an example of a tooltip using Smarty's popup function.
|
||||
|
||||
the value of $SCRIPT_NAME is {$SCRIPT_NAME}
|
||||
The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}
|
||||
|
||||
{* A simple variable test. print $Name in uppercase *}
|
||||
hello, my name is {$Name}
|
||||
Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME}
|
||||
|
||||
The value of {ldelim}$Name{rdelim} is <b>{$Name}</b>
|
||||
|
||||
variable modifier example of {ldelim}$Name|upper{rdelim}
|
||||
|
||||
<b>{$Name|upper}</b>
|
||||
|
||||
|
||||
An example of a section loop:
|
||||
|
||||
My interests are:
|
||||
{section name=outer loop=$FirstName}
|
||||
{if %outer.index% is odd by 2}
|
||||
{%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]}
|
||||
@@ -27,7 +34,8 @@ My interests are:
|
||||
none
|
||||
{/section}
|
||||
|
||||
testing section looped key values<br>
|
||||
An example of section looped key values:
|
||||
|
||||
{section name=sec1 loop=$contacts}
|
||||
phone: {$contacts[sec1].phone}<br>
|
||||
fax: {$contacts[sec1].fax}<br>
|
||||
|
Reference in New Issue
Block a user