mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
cleaning words spacing, killing tabulations, using roles for programlisting..
This commit is contained in:
@@ -10,17 +10,18 @@
|
||||
or malformed variable names. If this happens, you will see an error
|
||||
similar to the following:
|
||||
</para>
|
||||
|
||||
<example>
|
||||
<title>Smarty errors</title>
|
||||
<programlisting>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah'
|
||||
in /path/to/smarty/Smarty.class.php on line 1041
|
||||
|
||||
Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name
|
||||
in /path/to/smarty/Smarty.class.php on line 1041</programlisting>
|
||||
in /path/to/smarty/Smarty.class.php on line 1041
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
Smarty shows you the template name, the line number and the error.
|
||||
After that, the error consists of the actual line number in the Smarty
|
||||
@@ -35,8 +36,11 @@ Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name
|
||||
|
||||
<example>
|
||||
<title>PHP parsing errors</title>
|
||||
<programlisting>
|
||||
Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75</programlisting>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
@@ -67,7 +71,7 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
|
||||
<example>
|
||||
<title>Printing &nbsp; when a variable is empty</title>
|
||||
<programlisting>
|
||||
|
||||
<![CDATA[
|
||||
{* the long way *}
|
||||
|
||||
{if $title eq ""}
|
||||
@@ -79,7 +83,9 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
|
||||
|
||||
{* the short way *}
|
||||
|
||||
{$title|default:"&nbsp;"}</programlisting>
|
||||
{$title|default:"&nbsp;"}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
|
||||
@@ -94,11 +100,14 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
|
||||
<example>
|
||||
<title>Assigning a template variable its default value</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{* do this somewhere at the top of your template *}
|
||||
{assign var="title" value=$title|default:"no title"}
|
||||
|
||||
{* if $title was empty, it now contains the value "no title" when you print it *}
|
||||
{$title}</programlisting>
|
||||
{$title}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="tips.passing.vars">
|
||||
@@ -113,7 +122,7 @@ Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
|
||||
<example>
|
||||
<title>Passing the title variable to the header template</title>
|
||||
<programlisting>
|
||||
|
||||
<![CDATA[
|
||||
mainpage.tpl
|
||||
------------
|
||||
|
||||
@@ -143,7 +152,9 @@ header.tpl
|
||||
footer.tpl
|
||||
----------
|
||||
</BODY>
|
||||
</HTML></programlisting>
|
||||
</HTML>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
When the main page is drawn, the title of "Main Page" is passed to the
|
||||
@@ -171,6 +182,7 @@ footer.tpl
|
||||
<example>
|
||||
<title>using date_format</title>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{$startDate|date_format}
|
||||
|
||||
OUTPUT:
|
||||
@@ -187,7 +199,9 @@ OUTPUT:
|
||||
|
||||
{if $date1 < $date2}
|
||||
...
|
||||
{/if}</programlisting>
|
||||
{/if}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
When using {html_select_date} in a template, The programmer will most
|
||||
@@ -196,7 +210,8 @@ OUTPUT:
|
||||
</para>
|
||||
<example>
|
||||
<title>converting form date elements back to a timestamp</title>
|
||||
<programlisting>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
// this assumes your form elements are named
|
||||
// startDate_Day, startDate_Month, startDate_Year
|
||||
|
||||
@@ -212,7 +227,9 @@ function makeTimeStamp($year="",$month="",$day="")
|
||||
$day = strftime("%d");
|
||||
|
||||
return mktime(0,0,0,$month,$day,$year);
|
||||
}</programlisting>
|
||||
}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="tips.wap">
|
||||
@@ -227,7 +244,10 @@ function makeTimeStamp($year="",$month="",$day="")
|
||||
</para>
|
||||
<example>
|
||||
<title>using insert to write a WML Content-Type header</title>
|
||||
<programlisting>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
// be sure apache is configure for the .wml extensions!
|
||||
// put this function somewhere in your application, or in Smarty.addons.php
|
||||
function insert_header($params) {
|
||||
@@ -238,8 +258,14 @@ function insert_header($params) {
|
||||
return;
|
||||
}
|
||||
|
||||
// your Smarty template _must_ begin with the insert tag example:
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
your Smarty template <emphasis>must</emphasis> begin with the insert tag :
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
{insert name=header content="Content-Type: text/vnd.wap.wml"}
|
||||
|
||||
<?xml version="1.0"?>
|
||||
@@ -263,7 +289,9 @@ Press OK to continue...
|
||||
Pretty easy isn't it?
|
||||
</p>
|
||||
</card>
|
||||
</wml></programlisting>
|
||||
</wml>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="tips.componentized.templates">
|
||||
@@ -285,11 +313,11 @@ Pretty easy isn't it?
|
||||
</para>
|
||||
<example>
|
||||
<title>componentized template</title>
|
||||
<programlisting>
|
||||
function.load_ticker.php
|
||||
---------------
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
<?php
|
||||
// function.load_ticker.php
|
||||
function smarty_function_load_ticker($params, &$smarty) {
|
||||
// setup our function for fetching stock data
|
||||
function fetch_ticker($params['symbol']) {
|
||||
@@ -304,8 +332,11 @@ function smarty_function_load_ticker($params, &$smarty) {
|
||||
// assign template variable
|
||||
$smarty->assign($params['assign'],$ticker_info);
|
||||
}
|
||||
?>
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
index.tpl
|
||||
---------
|
||||
|
||||
@@ -313,7 +344,9 @@ index.tpl
|
||||
|
||||
{load_ticker symbol="YHOO" assign="ticker"}
|
||||
|
||||
Stock Name: {$ticker.name} Stock Price: {$ticker.price}</programlisting>
|
||||
Stock Name: {$ticker.name} Stock Price: {$ticker.price}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="tips.obfuscating.email">
|
||||
@@ -328,13 +361,13 @@ Stock Name: {$ticker.name} Stock Price: {$ticker.price}</programlisting>
|
||||
<example>
|
||||
<title>Example of Obfuscating an E-mail Address</title>
|
||||
<programlisting>
|
||||
|
||||
<![CDATA[
|
||||
index.tpl
|
||||
---------
|
||||
|
||||
Send inquiries to
|
||||
{mailto address=$EmailAddress encode="javascript" subject="Hello"}
|
||||
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<note>
|
||||
|
@@ -49,28 +49,78 @@
|
||||
Some of Smarty's features:
|
||||
</para>
|
||||
<itemizedlist>
|
||||
<listitem><para>It is extremely fast.</para></listitem>
|
||||
<listitem><para>It is efficient since the PHP parser does the
|
||||
dirty work.</para></listitem>
|
||||
<listitem><para>No template parsing overhead, only compiles once.</para></listitem>
|
||||
<listitem><para>It is smart about recompiling only the template
|
||||
files that have changed.</para></listitem>
|
||||
<listitem><para>You can make <link linkend="language.custom.functions">custom
|
||||
functions</link> and custom <link linkend="language.modifiers">variable
|
||||
modifiers</link>, so the template language is extremely extensible.</para></listitem>
|
||||
<listitem><para>Configurable template delimiter tag syntax, so you can use
|
||||
{}, {{}}, <!--{}-->, etc.</para></listitem>
|
||||
<listitem><para>The if/elseif/else/endif constructs are passed to the
|
||||
<listitem>
|
||||
<para>
|
||||
It is extremely fast.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
It is efficient since the PHP parser does the dirty work.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
No template parsing overhead, only compiles once.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
It is smart about recompiling only the template files that have changed.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
You can make <link linkend="language.custom.functions">custom functions</link>
|
||||
and custom <link linkend="language.modifiers">variable modifiers</link>, so the
|
||||
template language is extremely extensible.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Configurable template delimiter tag syntax, so you can use
|
||||
{}, {{}}, <!--{}-->, etc.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
The if/elseif/else/endif constructs are passed to the
|
||||
PHP parser, so the {if ...} expression syntax can be as simple or as complex
|
||||
as you like.</para></listitem>
|
||||
<listitem><para>Unlimited nesting of sections, ifs, etc. allowed.</para></listitem>
|
||||
<listitem><para>It is possible to embed PHP code right in your template files,
|
||||
as you like.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Unlimited nesting of sections, ifs, etc. allowed.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
It is possible to embed PHP code right in your template files,
|
||||
although this may not be needed (nor recommended)
|
||||
since the engine is so customizable.</para></listitem>
|
||||
<listitem><para>Built-in caching support</para></listitem>
|
||||
<listitem><para>Arbitrary template sources</para></listitem>
|
||||
<listitem><para>Custom cache handling functions</para></listitem>
|
||||
<listitem><para>Plugin architecture</para></listitem>
|
||||
since the engine is so customizable.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Built-in caching support
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Arbitrary template sources
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Custom cache handling functions
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Plugin architecture
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</chapter>
|
||||
<chapter id="installation">
|
||||
@@ -94,14 +144,16 @@
|
||||
<example>
|
||||
<title>Smarty library files</title>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Smarty.class.php
|
||||
Smarty_Compiler.class.php
|
||||
Config_File.class.php
|
||||
debug.tpl
|
||||
/core/*.php (all of them)
|
||||
/plugins/*.php (all of them)</screen>
|
||||
/plugins/*.php (all of them)
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
Smarty uses a PHP constant named <link
|
||||
linkend="constant.smarty.dir">SMARTY_DIR</link> which is the system
|
||||
@@ -119,9 +171,14 @@ debug.tpl
|
||||
|
||||
<example>
|
||||
<title>Create Smarty instance of Smarty</title>
|
||||
<screen>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
require('Smarty.class.php');
|
||||
$smarty = new Smarty;</screen>
|
||||
$smarty = new Smarty;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
@@ -132,27 +189,42 @@ $smarty = new Smarty;</screen>
|
||||
|
||||
<example>
|
||||
<title>Supply absolute path to library file</title>
|
||||
<screen>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
require('/usr/local/lib/php/Smarty/Smarty.class.php');
|
||||
$smarty = new Smarty;</screen>
|
||||
$smarty = new Smarty;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>Add library directory to php_include path</title>
|
||||
<screen>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// Edit your php.ini file, add the Smarty library
|
||||
// directory to the include_path and restart web server.
|
||||
// Then the following should work:
|
||||
require('Smarty.class.php');
|
||||
$smarty = new Smarty;</screen>
|
||||
$smarty = new Smarty;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>Set SMARTY_DIR constant manually</title>
|
||||
<screen>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
define('SMARTY_DIR', '/usr/local/lib/php/Smarty/');
|
||||
require(SMARTY_DIR . 'Smarty.class.php');
|
||||
$smarty = new Smarty;</screen>
|
||||
$smarty = new Smarty;
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
@@ -209,6 +281,7 @@ $smarty = new Smarty;</screen>
|
||||
<example>
|
||||
<title>Example file structure</title>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
/usr/local/lib/php/Smarty/Smarty.class.php
|
||||
/usr/local/lib/php/Smarty/Smarty_Compiler.class.php
|
||||
/usr/local/lib/php/Smarty/Config_File.class.php
|
||||
@@ -221,7 +294,9 @@ $smarty = new Smarty;</screen>
|
||||
/web/www.mydomain.com/smarty/guestbook/configs/
|
||||
/web/www.mydomain.com/smarty/guestbook/cache/
|
||||
|
||||
/web/www.mydomain.com/docs/guestbook/index.php</screen>
|
||||
/web/www.mydomain.com/docs/guestbook/index.php
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
@@ -235,13 +310,15 @@ $smarty = new Smarty;</screen>
|
||||
|
||||
<example>
|
||||
<title>Setting file permissions</title>
|
||||
<screen>
|
||||
|
||||
<programlisting role="shell">
|
||||
<![CDATA[
|
||||
chown nobody:nobody /web/www.mydomain.com/smarty/guestbook/templates_c/
|
||||
chmod 770 /web/www.mydomain.com/smarty/guestbook/templates_c/
|
||||
|
||||
chown nobody:nobody /web/www.mydomain.com/smarty/guestbook/cache/
|
||||
chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/</screen>
|
||||
chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<note>
|
||||
@@ -262,13 +339,15 @@ chmod 770 /web/www.mydomain.com/smarty/guestbook/cache/</screen>
|
||||
<example>
|
||||
<title>Editing /web/www.mydomain.com/smarty/guestbook/templates/index.tpl</title>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
|
||||
{* Smarty *}
|
||||
|
||||
Hello, {$name}!</screen>
|
||||
Hello, {$name}!
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
|
||||
<note>
|
||||
<title>Technical Note</title>
|
||||
<para>
|
||||
@@ -289,7 +368,10 @@ Hello, {$name}!</screen>
|
||||
|
||||
<example>
|
||||
<title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title>
|
||||
<screen>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
// load Smarty library
|
||||
require('Smarty.class.php');
|
||||
|
||||
@@ -302,7 +384,10 @@ $smarty->cache_dir = '/web/www.mydomain.com/smarty/guestbook/cache/';
|
||||
|
||||
$smarty->assign('name','Ned');
|
||||
|
||||
$smarty->display('index.tpl');</screen>
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<note>
|
||||
@@ -344,7 +429,9 @@ $smarty->display('index.tpl');</screen>
|
||||
|
||||
<example>
|
||||
<title>Editing /php/includes/guestbook/setup.php</title>
|
||||
<screen>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
// load Smarty library
|
||||
require('Smarty.class.php');
|
||||
@@ -371,7 +458,10 @@ class Smarty_GuestBook extends Smarty {
|
||||
$this->assign('app_name','Guest Book');
|
||||
}
|
||||
|
||||
}</screen>
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
@@ -380,7 +470,9 @@ class Smarty_GuestBook extends Smarty {
|
||||
|
||||
<example>
|
||||
<title>Editing /web/www.mydomain.com/docs/guestbook/index.php</title>
|
||||
<screen>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
require('guestbook/setup.php');
|
||||
|
||||
@@ -388,7 +480,10 @@ $smarty = new Smarty_GuestBook;
|
||||
|
||||
$smarty->assign('name','Ned');
|
||||
|
||||
$smarty->display('index.tpl');</screen>
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
<para>
|
||||
|
Reference in New Issue
Block a user