mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
Clean up WS, more linking and examples
This commit is contained in:
@@ -3,11 +3,16 @@
|
||||
<chapter id="config.files">
|
||||
<title>Config Files</title>
|
||||
<para>
|
||||
Config files are handy for designers to manage global template
|
||||
variables from one file. One example is template colors. Normally if
|
||||
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
|
||||
Config files are handy for designers to manage global
|
||||
template
|
||||
variables from one file. One example is template colors.
|
||||
Normally if
|
||||
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.
|
||||
</para>
|
||||
<example>
|
||||
@@ -41,42 +46,75 @@ pass=foobar
|
||||
</example>
|
||||
<para>
|
||||
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.
|
||||
You can use either single or double quotes. If you have a value that
|
||||
spans more than one line, enclose the entire value with 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>
|
||||
You can use either single or double quotes. If you have a
|
||||
value that
|
||||
spans more than one line, enclose the entire value with
|
||||
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.
|
||||
</para>
|
||||
<para>
|
||||
This config file example has two sections. Section names are enclosed in
|
||||
brackets []. Section names can be arbitrary strings not containing
|
||||
<literal>[</literal> or <literal>]</literal> symbols. The four variables
|
||||
at the top are global variables, or variables not within a section.
|
||||
These variables are always loaded from the config file. If a 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. (see
|
||||
<link linkend="variable.config.overwrite">$config_overwrite</link>)
|
||||
This config file example has two sections. Section names are
|
||||
enclosed in
|
||||
brackets []. Section names can be arbitrary strings not
|
||||
containing
|
||||
<literal>[</literal> or <literal>]</literal> symbols. The
|
||||
four variables
|
||||
at the top are global variables, or variables not within a
|
||||
section.
|
||||
These variables are always loaded from the config file. If a
|
||||
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>
|
||||
Config files are loaded into templates with the built-in function
|
||||
Config files are loaded into templates with the built-in
|
||||
function
|
||||
<link
|
||||
linkend="language.function.config.load"><command>{config_load}</command></link>
|
||||
, and
|
||||
linkend="language.function.config.load"><command>
|
||||
{config_load}</command></link>
|
||||
(see also
|
||||
<link
|
||||
linkend="api.config.load"><command>config_load()</command></link>.
|
||||
linkend="api.config.load"><command>config_load()</command></link> ).
|
||||
</para>
|
||||
<para>
|
||||
You can hide variables or entire sections by prepending the variable
|
||||
name or section name with a period. This is useful if your application
|
||||
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
|
||||
You can hide variables or entire sections by prepending the
|
||||
variable
|
||||
name or section name with a period. This is useful if your
|
||||
application
|
||||
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.
|
||||
</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>
|
||||
|
||||
<!-- 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
|
||||
vi: ts=1 sw=1
|
||||
-->
|
||||
|
||||
|
@@ -109,8 +109,8 @@
|
||||
|
||||
<example>
|
||||
<title>{include} and assign to variable</title>
|
||||
<para>This example assign the contents of nav.tpl to a variable
|
||||
and outputs at the top of page and the bottom.
|
||||
<para>This example assigns the contents of nav.tpl to the $navbar variable,
|
||||
which is then output at the top and bottom of the page.
|
||||
</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
@@ -124,7 +124,7 @@
|
||||
{include file="footer.tpl" logo="http://my.example.com/logo.gif"}
|
||||
{$navbar}
|
||||
</body>
|
||||
]]>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
|
@@ -29,6 +29,29 @@
|
||||
{funcname} is how functions look in Smarty!
|
||||
]]>
|
||||
</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>
|
||||
<para>See also <link linkend="language.escaping">Escaping Smarty Parsing</link> </para>
|
||||
</sect1>
|
||||
|
@@ -19,19 +19,17 @@
|
||||
<![CDATA[
|
||||
{literal}
|
||||
<script type="text/javascript">
|
||||
|
||||
<!--
|
||||
function isblank(field) {
|
||||
if (field.value == '')
|
||||
{ return false; }
|
||||
else
|
||||
{
|
||||
document.loginform.submit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// -->
|
||||
|
||||
<!--
|
||||
function isblank(field) {
|
||||
if (field.value == '')
|
||||
{ return false; }
|
||||
else
|
||||
{
|
||||
document.loginform.submit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// -->
|
||||
</script>
|
||||
{/literal}
|
||||
]]>
|
||||
|
@@ -95,7 +95,8 @@ $smarty->assign('cust_names', array(
|
||||
'Joe Schmoe',
|
||||
'Jack Smith',
|
||||
'Jane Johnson',
|
||||
'Charlie Brown'));
|
||||
'Charlie Brown')
|
||||
);
|
||||
$smarty->assign('customer_id', 1001);
|
||||
|
||||
?>
|
||||
@@ -118,10 +119,11 @@ where template is
|
||||
<?php
|
||||
|
||||
$smarty->assign('cust_checkboxes', array(
|
||||
1000 => 'Joe Schmoe',
|
||||
1001 => 'Jack Smith',
|
||||
1002 => 'Jane Johnson',
|
||||
1003 => 'Charlie Brown'));
|
||||
1000 => 'Joe Schmoe',
|
||||
1001 => 'Jack Smith',
|
||||
1002 => 'Jane Johnson',
|
||||
1003 => 'Charlie Brown')
|
||||
);
|
||||
$smarty->assign('customer_id', 1001);
|
||||
|
||||
?>
|
||||
|
@@ -215,10 +215,11 @@ Monday, February 5, 2001
|
||||
<note>
|
||||
<title>Programmers note</title>
|
||||
<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.
|
||||
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.
|
||||
</para>
|
||||
</note>
|
||||
|
@@ -69,7 +69,9 @@ $smarty->assign('Contacts',
|
||||
array('fax' => '555-222-9876',
|
||||
'email' => 'zaphod@slartibartfast.com',
|
||||
'phone' => array('home' => '555-444-3333',
|
||||
'cell' => '555-111-1234')));
|
||||
'cell' => '555-111-1234')
|
||||
)
|
||||
);
|
||||
$smarty->display('index.tpl');
|
||||
?>
|
||||
]]>
|
||||
@@ -110,7 +112,6 @@ zaphod@slartibartfast.com<br />
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$smarty->assign('Contacts', array(
|
||||
'555-222-9876',
|
||||
'zaphod@slartibartfast.com',
|
||||
@@ -118,7 +119,6 @@ $smarty->assign('Contacts', array(
|
||||
'555-111-1234')
|
||||
));
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
@@ -1,13 +1,58 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision$ -->
|
||||
<sect1 id="variable.config.overwrite">
|
||||
<title>$config_overwrite</title>
|
||||
<para>
|
||||
If set to true, variables read in from config files will overwrite each
|
||||
other. Otherwise, the variables will be pushed onto an array. This is
|
||||
helpful if you want to store arrays of data in config files, just list
|
||||
each element multiple times. true by default.
|
||||
<sect1 id="variable.config.overwrite">
|
||||
<title>$config_overwrite</title>
|
||||
<para>
|
||||
If set to true (by default), variables read in from
|
||||
<link linkend="config.files">config files</link> will overwrite each
|
||||
other. Otherwise, the variables will be pushed onto an array. This is
|
||||
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>
|
||||
<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>
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
|
Reference in New Issue
Block a user