mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
Clean up WS, more linking and examples
This commit is contained in:
@@ -3,11 +3,16 @@
|
|||||||
<chapter id="config.files">
|
<chapter id="config.files">
|
||||||
<title>Config Files</title>
|
<title>Config Files</title>
|
||||||
<para>
|
<para>
|
||||||
Config files are handy for designers to manage global template
|
Config files are handy for designers to manage global
|
||||||
variables from one file. One example is template colors. Normally if
|
template
|
||||||
you wanted to change the color scheme of an application, you would have
|
variables from one file. One example is template colors.
|
||||||
to go through each and every template file and change the colors. With
|
Normally if
|
||||||
a config file, the colors can be kept in one place, and only one file
|
you wanted to change the color scheme of an application, you
|
||||||
|
would have
|
||||||
|
to go through each and every template file and change the
|
||||||
|
colors. With
|
||||||
|
a config file, the colors can be kept in one place, and only
|
||||||
|
one file
|
||||||
needs to be updated.
|
needs to be updated.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
@@ -41,42 +46,75 @@ pass=foobar
|
|||||||
</example>
|
</example>
|
||||||
<para>
|
<para>
|
||||||
Values of
|
Values of
|
||||||
<link linkend="language.config.variables">config file variables</link>
|
<link linkend="language.config.variables">config file
|
||||||
|
variables</link>
|
||||||
can be in quotes, but not necessary.
|
can be in quotes, but not necessary.
|
||||||
You can use either single or double quotes. If you have a value that
|
You can use either single or double quotes. If you have a
|
||||||
spans more than one line, enclose the entire value with triple quotes
|
value that
|
||||||
("""). You can put comments into config files by any syntax that is not
|
spans more than one line, enclose the entire value with
|
||||||
a valid config file syntax. We recommend using a <literal>#</literal>
|
triple quotes
|
||||||
|
("""). You can put comments into config files by any syntax
|
||||||
|
that is not
|
||||||
|
a valid config file syntax. We recommend using a <literal>
|
||||||
|
#</literal>
|
||||||
(hash) at the beginning of the line.
|
(hash) at the beginning of the line.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
This config file example has two sections. Section names are enclosed in
|
This config file example has two sections. Section names are
|
||||||
brackets []. Section names can be arbitrary strings not containing
|
enclosed in
|
||||||
<literal>[</literal> or <literal>]</literal> symbols. The four variables
|
brackets []. Section names can be arbitrary strings not
|
||||||
at the top are global variables, or variables not within a section.
|
containing
|
||||||
These variables are always loaded from the config file. If a particular
|
<literal>[</literal> or <literal>]</literal> symbols. The
|
||||||
section is loaded, then the global variables and the variables from that
|
four variables
|
||||||
section are also loaded. If a variable exists both as a global and in a
|
at the top are global variables, or variables not within a
|
||||||
section, the section variable is used. If you name two variables the
|
section.
|
||||||
same within a section, the last one will be used. (see
|
These variables are always loaded from the config file. If a
|
||||||
<link linkend="variable.config.overwrite">$config_overwrite</link>)
|
particular
|
||||||
|
section is loaded, then the global variables and the
|
||||||
|
variables from that
|
||||||
|
section are also loaded. If a variable exists both as a
|
||||||
|
global and in a
|
||||||
|
section, the section variable is used. If you name two
|
||||||
|
variables the
|
||||||
|
same within a section, the last one will be used unless
|
||||||
|
<link linkend="variable.config.overwrite">
|
||||||
|
$config_overwrite</link>
|
||||||
|
is disabled.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Config files are loaded into templates with the built-in function
|
Config files are loaded into templates with the built-in
|
||||||
|
function
|
||||||
<link
|
<link
|
||||||
linkend="language.function.config.load"><command>{config_load}</command></link>
|
linkend="language.function.config.load"><command>
|
||||||
, and
|
{config_load}</command></link>
|
||||||
|
(see also
|
||||||
<link
|
<link
|
||||||
linkend="api.config.load"><command>config_load()</command></link>.
|
linkend="api.config.load"><command>config_load()</command></link> ).
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
You can hide variables or entire sections by prepending the variable
|
You can hide variables or entire sections by prepending the
|
||||||
name or section name with a period. This is useful if your application
|
variable
|
||||||
reads the config files and gets sensitive data from them that the
|
name or section name with a period. This is useful if your
|
||||||
template engine does not need. If you have third parties doing template
|
application
|
||||||
editing, you can be certain that they cannot read sensitive data from
|
reads the config files and gets sensitive data from them
|
||||||
|
that the
|
||||||
|
template engine does not need. If you have third parties
|
||||||
|
doing template
|
||||||
|
editing, you can be certain that they cannot read sensitive
|
||||||
|
data from
|
||||||
the config file by loading it into the template.
|
the config file by loading it into the template.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
See also
|
||||||
|
<link linkend="language.function.config.load">{config_load}</link>,
|
||||||
|
<link linkend="variable.config.overwrite">$config_overwrite</link>,
|
||||||
|
<link linkend="api.get.config.vars">get_config_vars()</link>,
|
||||||
|
<link linkend="api.clear.config">clear_config()</link>
|
||||||
|
and
|
||||||
|
<link linkend="api.config.load">config_load()</link>
|
||||||
|
</para>
|
||||||
|
|
||||||
</chapter>
|
</chapter>
|
||||||
|
|
||||||
<!-- Keep this comment at the end of the file
|
<!-- Keep this comment at the end of the file
|
||||||
@@ -99,3 +137,4 @@ 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
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
@@ -109,8 +109,8 @@
|
|||||||
|
|
||||||
<example>
|
<example>
|
||||||
<title>{include} and assign to variable</title>
|
<title>{include} and assign to variable</title>
|
||||||
<para>This example assign the contents of nav.tpl to a variable
|
<para>This example assigns the contents of nav.tpl to the $navbar variable,
|
||||||
and outputs at the top of page and the bottom.
|
which is then output at the top and bottom of the page.
|
||||||
</para>
|
</para>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
{include file="footer.tpl" logo="http://my.example.com/logo.gif"}
|
{include file="footer.tpl" logo="http://my.example.com/logo.gif"}
|
||||||
{$navbar}
|
{$navbar}
|
||||||
</body>
|
</body>
|
||||||
]]>
|
]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
|
|
||||||
|
@@ -29,6 +29,29 @@
|
|||||||
{funcname} is how functions look in Smarty!
|
{funcname} is how functions look in Smarty!
|
||||||
]]>
|
]]>
|
||||||
</screen>
|
</screen>
|
||||||
|
<para>Another example with some javascript</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
<script language="JavaScript">
|
||||||
|
function foo() {ldelim}
|
||||||
|
... code ...
|
||||||
|
{rdelim}
|
||||||
|
</script>
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
will output
|
||||||
|
</para>
|
||||||
|
<screen>
|
||||||
|
<![CDATA[
|
||||||
|
<script language="JavaScript">
|
||||||
|
function foo() {
|
||||||
|
.... code ...
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
]]>
|
||||||
|
</screen>
|
||||||
|
|
||||||
</example>
|
</example>
|
||||||
<para>See also <link linkend="language.escaping">Escaping Smarty Parsing</link> </para>
|
<para>See also <link linkend="language.escaping">Escaping Smarty Parsing</link> </para>
|
||||||
</sect1>
|
</sect1>
|
||||||
|
@@ -19,19 +19,17 @@
|
|||||||
<![CDATA[
|
<![CDATA[
|
||||||
{literal}
|
{literal}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
<!--
|
||||||
<!--
|
function isblank(field) {
|
||||||
function isblank(field) {
|
if (field.value == '')
|
||||||
if (field.value == '')
|
{ return false; }
|
||||||
{ return false; }
|
else
|
||||||
else
|
{
|
||||||
{
|
document.loginform.submit();
|
||||||
document.loginform.submit();
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
}
|
// -->
|
||||||
// -->
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{/literal}
|
{/literal}
|
||||||
]]>
|
]]>
|
||||||
|
@@ -95,7 +95,8 @@ $smarty->assign('cust_names', array(
|
|||||||
'Joe Schmoe',
|
'Joe Schmoe',
|
||||||
'Jack Smith',
|
'Jack Smith',
|
||||||
'Jane Johnson',
|
'Jane Johnson',
|
||||||
'Charlie Brown'));
|
'Charlie Brown')
|
||||||
|
);
|
||||||
$smarty->assign('customer_id', 1001);
|
$smarty->assign('customer_id', 1001);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -118,10 +119,11 @@ where template is
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$smarty->assign('cust_checkboxes', array(
|
$smarty->assign('cust_checkboxes', array(
|
||||||
1000 => 'Joe Schmoe',
|
1000 => 'Joe Schmoe',
|
||||||
1001 => 'Jack Smith',
|
1001 => 'Jack Smith',
|
||||||
1002 => 'Jane Johnson',
|
1002 => 'Jane Johnson',
|
||||||
1003 => 'Charlie Brown'));
|
1003 => 'Charlie Brown')
|
||||||
|
);
|
||||||
$smarty->assign('customer_id', 1001);
|
$smarty->assign('customer_id', 1001);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@@ -215,10 +215,11 @@ Monday, February 5, 2001
|
|||||||
<note>
|
<note>
|
||||||
<title>Programmers note</title>
|
<title>Programmers note</title>
|
||||||
<para>
|
<para>
|
||||||
date_format is essentially a wrapper to PHP's
|
<command>date_format</command> is essentially a wrapper to PHP's
|
||||||
<ulink url="&url.php-manual;strftime">strftime()</ulink> function.
|
<ulink url="&url.php-manual;strftime">strftime()</ulink> function.
|
||||||
You may have more or less conversion specifiers available depending
|
You may have more or less conversion specifiers available depending
|
||||||
on your system's strftime() function where PHP was compiled. Check your
|
on your system's <ulink url="&url.php-manual;strftime">strftime()</ulink>
|
||||||
|
function where PHP was compiled. Check your
|
||||||
system's manpage for a full list of valid specifiers.
|
system's manpage for a full list of valid specifiers.
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
@@ -69,7 +69,9 @@ $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');
|
||||||
?>
|
?>
|
||||||
]]>
|
]]>
|
||||||
@@ -110,7 +112,6 @@ zaphod@slartibartfast.com<br />
|
|||||||
<programlisting role="php">
|
<programlisting role="php">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$smarty->assign('Contacts', array(
|
$smarty->assign('Contacts', array(
|
||||||
'555-222-9876',
|
'555-222-9876',
|
||||||
'zaphod@slartibartfast.com',
|
'zaphod@slartibartfast.com',
|
||||||
@@ -118,7 +119,6 @@ $smarty->assign('Contacts', array(
|
|||||||
'555-111-1234')
|
'555-111-1234')
|
||||||
));
|
));
|
||||||
$smarty->display('index.tpl');
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
]]>
|
]]>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
@@ -1,13 +1,58 @@
|
|||||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||||
<!-- $Revision$ -->
|
<!-- $Revision$ -->
|
||||||
<sect1 id="variable.config.overwrite">
|
<sect1 id="variable.config.overwrite">
|
||||||
<title>$config_overwrite</title>
|
<title>$config_overwrite</title>
|
||||||
<para>
|
<para>
|
||||||
If set to true, variables read in from config files will overwrite each
|
If set to true (by default), variables read in from
|
||||||
other. Otherwise, the variables will be pushed onto an array. This is
|
<link linkend="config.files">config files</link> will overwrite each
|
||||||
helpful if you want to store arrays of data in config files, just list
|
other. Otherwise, the variables will be pushed onto an array. This is
|
||||||
each element multiple times. true by default.
|
helpful if you want to store arrays of data in config files, just list
|
||||||
|
each element multiple times.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<example>
|
||||||
|
<title>Array of config variables</title>
|
||||||
|
<para>
|
||||||
|
This examples uses
|
||||||
|
<link linkend="language.function.cycle">{cycle}</link> to
|
||||||
|
ouput a table with alternating red/gree/blue row colors
|
||||||
|
with $config_overwrite = false.
|
||||||
|
</para>
|
||||||
|
<para>The config file.</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
# row colors
|
||||||
|
rowColors = #FF0000
|
||||||
|
rowColors = #00FF00
|
||||||
|
rowColors = #0000FF
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
<para>
|
||||||
|
The template with a
|
||||||
|
<link linkend="language.function.section">{section}</link> loop.
|
||||||
</para>
|
</para>
|
||||||
|
<programlisting>
|
||||||
|
<![CDATA[
|
||||||
|
<table>
|
||||||
|
{section name=r loop=$rows}
|
||||||
|
<tr bgcolor="{cycle values=#rowColors#}">
|
||||||
|
<td> ....etc.... </td>
|
||||||
|
</tr>
|
||||||
|
{/section}
|
||||||
|
</table>
|
||||||
|
]]>
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
<para>
|
||||||
|
See also
|
||||||
|
<link linkend="language.function.config.load">{config_load}</link>,
|
||||||
|
<link linkend="config.files">config files</link>,
|
||||||
|
<link linkend="api.get.config.vars">get_config_vars()</link>,
|
||||||
|
<link linkend="api.clear.config">clear_config()</link>
|
||||||
|
and
|
||||||
|
<link linkend="api.config.load">config_load()</link>.
|
||||||
|
</para>
|
||||||
|
|
||||||
</sect1>
|
</sect1>
|
||||||
<!-- Keep this comment at the end of the file
|
<!-- Keep this comment at the end of the file
|
||||||
Local variables:
|
Local variables:
|
||||||
|
Reference in New Issue
Block a user