mirror of
https://github.com/smarty-php/smarty.git
synced 2026-04-28 18:02:07 +02:00
update Smarty version numbers
This commit is contained in:
@@ -362,9 +362,7 @@ Stock Name: {$ticker_name} Stock Price: {$ticker_price}</programlisting>
|
||||
lists? One way spammers collect E-mail addresses is from web pages. To
|
||||
help combat this problem, you can make your E-mail address show up in
|
||||
scrambled javascript in the HTML source, yet it it will look and work
|
||||
correctly in the browser. This is done with the mailto plugin,
|
||||
available from the plugin repository on the Smarty website. Download
|
||||
the plugin and drop it into the plugins directory.
|
||||
correctly in the browser. This is done with the mailto plugin.
|
||||
</para>
|
||||
<example>
|
||||
<title>Example of Obfuscating an E-mail Address</title>
|
||||
|
||||
+156
-8
@@ -359,6 +359,18 @@ OUTPUT:
|
||||
<programlisting>
|
||||
{* use the date_format modifier to show current date and time *}
|
||||
{$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>
|
||||
</sect2>
|
||||
|
||||
@@ -395,8 +407,8 @@ OUTPUT:
|
||||
<chapter id="language.modifiers">
|
||||
<title>Variable Modifiers</title>
|
||||
<para>
|
||||
Variable modifiers can be applied to any variable to alter its contents. To
|
||||
apply a modifier, specify the variable followed by the <literal>|</literal>
|
||||
Variable modifiers can be applied to variables, custom functions or strings. To
|
||||
apply a modifier, specify the value followed by the <literal>|</literal>
|
||||
(pipe) and the modifier name. A modifier may accept additional parameters
|
||||
that affect its behavior. These parameters follow the modifer name and are
|
||||
separated by <literal>:</literal> (colon).
|
||||
@@ -408,7 +420,13 @@ OUTPUT:
|
||||
<h2>{$title|upper}</h2>
|
||||
|
||||
{* Truncate the topic to 40 characters use ... at the end *}
|
||||
Topic: {$topic|truncate:40:"..."}</programlisting>
|
||||
Topic: {$topic|truncate:40:"..."}
|
||||
|
||||
{* format a literal string *}
|
||||
{"now"|date_format:"%Y/%m/%d"}
|
||||
|
||||
{* apply modifier to a custom function *}
|
||||
{mailto|upper address="me@domain.dom"}</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
If you apply a modifier to an array variable instead of a single value variable,
|
||||
@@ -787,7 +805,7 @@ no title</programlisting>
|
||||
<entry>1</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry>html,htmlall,url,quotes,hex,hexentity</entry>
|
||||
<entry>html,htmlall,url,quotes,hex,hexentity,javascript</entry>
|
||||
<entry>html</entry>
|
||||
<entry>This is the escape format to use.</entry>
|
||||
</row>
|
||||
@@ -796,10 +814,8 @@ no title</programlisting>
|
||||
</informaltable>
|
||||
<para>
|
||||
This is used to html escape, url escape, escape single quotes on a
|
||||
variable not already escaped, hex escape or hexentity escape. hex
|
||||
and hexentity escape can be used in conjunction to hide "mailto:"
|
||||
links on a page from web spiders (spam collectors) and yet keep
|
||||
them readable and linkable. By default, the variable is html
|
||||
variable not already escaped, hex escape, hexentity or javascript escape.
|
||||
By default, the variable is html
|
||||
escaped.
|
||||
</para>
|
||||
<example>
|
||||
@@ -4128,6 +4144,138 @@ OUTPUT:
|
||||
OUTPUT:
|
||||
|
||||
9.44</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="language.function.mailto">
|
||||
<title>mailto</title>
|
||||
<informaltable frame=all>
|
||||
<tgroup cols=5>
|
||||
<colspec colname=param align=center>
|
||||
<colspec colname=type align=center>
|
||||
<colspec colname=required align=center>
|
||||
<colspec colname=default align=center>
|
||||
<colspec colname=desc>
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Attribute Name</entry>
|
||||
<entry>Type</entry>
|
||||
<entry>Required</entry>
|
||||
<entry>Default</entry>
|
||||
<entry>Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>address</entry>
|
||||
<entry>string</entry>
|
||||
<entry>Yes</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>the e-mail address</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>text</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>the text to display, default is
|
||||
the e-mail address</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>encode</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>none</emphasis></entry>
|
||||
<entry>How to encode the e-mail.
|
||||
Can be one of none,
|
||||
hex or javascript.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>cc</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>e-mail addresses to carbon copy.
|
||||
Separate entries by a comma.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>bcc</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>e-mail addresses to blind carbon copy.
|
||||
Separate entries by a comma.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>subject</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>e-mail subject.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>newsgroups</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>newsgroups to post to.
|
||||
Separate entries by a comma.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>followupto</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>addresses to follow up to.
|
||||
Separate entries by a comma.</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>extra</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>any extra information you
|
||||
want passed to the link, such
|
||||
as style sheet classes</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
<para>
|
||||
mailto automates the creation of mailto links and optionally
|
||||
encodes them. Encoding e-mails makes it more difficult for
|
||||
web spiders to pick up e-mail addresses off of your site.
|
||||
</para>
|
||||
<note>
|
||||
<title>Technical Note</title>
|
||||
<para>
|
||||
javascript is probably the most thorough form of
|
||||
encoding, although you can use hex encoding too.
|
||||
</para>
|
||||
</note>
|
||||
<example>
|
||||
<title>mailto</title>
|
||||
<programlisting>
|
||||
{mailto address="me@domain.com"}
|
||||
{mailto address="me@domain.com" text="send me some mail"}
|
||||
{mailto address="me@domain.com" encode="javascript"}
|
||||
{mailto address="me@domain.com" encode="hex"}
|
||||
{mailto address="me@domain.com" subject="Hello to you!"}
|
||||
{mailto address="me@domain.com" cc="you@domain.com,they@domain.com"}
|
||||
{mailto address="me@domain.com" extra='class="email"'}
|
||||
|
||||
OUTPUT:
|
||||
|
||||
<a href="mailto:me@domain.com" >me@domain.com</a>
|
||||
<a href="mailto:me@domain.com" >send me some mail</a>
|
||||
<SCRIPT language="javascript">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%6
|
||||
9%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%
|
||||
61%69%6e%2e%63%6f%6d%22%20%3e%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%3c%2f%61%3e
|
||||
%27%29%3b'))</SCRIPT>
|
||||
<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d" >&#x6d;&#x65;&#x40;&#x64;&
|
||||
#x6f;&#x6d;&#x61;&#x69;&#x6e;&#x2e;&#x63;&#x6f;&#x6d;</a>
|
||||
<a href="mailto:me@domain.com?subject=Hello%20to%20you%21" >me@domain.com</a>
|
||||
<a href="mailto:me@domain.com?cc=you@domain.com%2Cthey@domain.com" >me@domain.com</a>
|
||||
<a href="mailto:me@domain.com" class="email">me@domain.com</a></programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="language.function.popup.init">
|
||||
|
||||
+100
-2
@@ -1125,6 +1125,23 @@ $smarty->register_modifier("sslash","stripslashes");
|
||||
|
||||
// now you can use {$var|sslash} to strip slashes from variables</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="api.register.object">
|
||||
<title>register_object</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>void <function>register_object</function></funcdef>
|
||||
<paramdef>string <parameter>object_name</parameter></paramdef>
|
||||
<paramdef>object <parameter>$object</parameter></paramdef>
|
||||
<paramdef>array <parameter>allowed methods/properties</parameter></paramdef>
|
||||
<paramdef>boolean <parameter>format</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
This is to register an object for use in the templates. See the
|
||||
<link linkend="advanced.features.objects">object section</link>
|
||||
of the manual for examples.
|
||||
</para>
|
||||
</sect1>
|
||||
<sect1 id="api.register.outputfilter">
|
||||
<title>register_outputfilter</title>
|
||||
@@ -1295,6 +1312,18 @@ $smarty->unregister_function("fetch");</programlisting>
|
||||
$smarty->unregister_modifier("strip_tags");</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="api.unregister.object">
|
||||
<title>unregister_object</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>void <function>unregister_object</function></funcdef>
|
||||
<paramdef>string <parameter>object_name</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
Use this to unregister an object.
|
||||
</para>
|
||||
</sect1>
|
||||
<sect1 id="api.unregister.outputfilter">
|
||||
<title>unregister_outputfilter</title>
|
||||
<funcsynopsis>
|
||||
@@ -1639,6 +1668,75 @@ $smarty->display('index.tpl',"sports|basketball");</programlisting>
|
||||
|
||||
<chapter id="advanced.features">
|
||||
<title>Advanced Features</title>
|
||||
<sect1 id="advanced.features.objects">
|
||||
<title>Objects</title>
|
||||
<para>
|
||||
Smarty allows access to PHP objects through the templates. There are
|
||||
two ways to access them. One way is to register objects to the template,
|
||||
then use access them via syntax similar to custom functions. The other way
|
||||
is to assign objects to the templates and access them much like any other
|
||||
assigned variable. The first method has a much nicer template syntax. It
|
||||
is also more secure, as a registered object can be restricted to certain
|
||||
methods or properties. However, a registered object cannot be looped over
|
||||
or assigned in arrays of objects, etc. The method you choose will be
|
||||
determined by your needs, but use the first method whenever possible to
|
||||
keep template syntax to a minimum.
|
||||
</para>
|
||||
<para>
|
||||
If security is enabled, no private methods or functions can be accessed
|
||||
(begininning with "_"). If a method and property of the same name exist,
|
||||
the method will be used.
|
||||
</para>
|
||||
<para>
|
||||
You can restrict the methods and properties that can be accessed by
|
||||
listing them in an array as the third registration parameter.
|
||||
</para>
|
||||
<para>
|
||||
By default, parameters passed to objects through the templates are passed
|
||||
the same way custom functions get them. An associative array is passed
|
||||
as the first parameter, and the smarty object as the second. If you want
|
||||
the parameters passed one at a time for each argument like traditional
|
||||
object parameter passing, set the fourth registration parameter to false.
|
||||
</para>
|
||||
<example>
|
||||
<title>using a registered or assigned object</title>
|
||||
<programlisting>
|
||||
<?php
|
||||
// the object
|
||||
|
||||
class My_Object() {
|
||||
function meth1($params, &$smarty_obj) {
|
||||
return "this is my meth1";
|
||||
}
|
||||
}
|
||||
|
||||
$myobj = new My_Object;
|
||||
// registering the object (will be by reference)
|
||||
$smarty->register_object("foobar",$myobj);
|
||||
// if we want to restrict access to certain methods or properties, list them
|
||||
$smarty->register_object("foobar",$myobj,array('meth1','meth2','prop1'));
|
||||
// if you want to use the traditional object parameter format, pass a boolean of false
|
||||
$smarty->register_object("foobar",$myobj,null,false);
|
||||
|
||||
// We can also assign objects. Assign by ref when possible.
|
||||
$smarty->assign_by_ref("myobj", $myobj);
|
||||
|
||||
$smarty->display("index.tpl");
|
||||
?>
|
||||
|
||||
TEMPLATE:
|
||||
|
||||
{* access our registered object *}
|
||||
{foobar->meth1 p1="foo" p2=$bar}
|
||||
|
||||
{* you can also assign the output *}
|
||||
{foobar->meth1 p1="foo" p2=$bar assign="output"}
|
||||
the output was {$output)
|
||||
|
||||
{* access our assigned object *}
|
||||
{$myobj->meth1("foo",$bar)}</programlisting>
|
||||
</example>
|
||||
</sect1>
|
||||
<sect1 id="advanced.features.prefilters">
|
||||
<title>Prefilters</title>
|
||||
<para>
|
||||
@@ -2219,7 +2317,7 @@ require_once SMARTY_DIR . 'plugins/function.html_options.php';</programlisting>
|
||||
table.
|
||||
</para>
|
||||
<para>
|
||||
The output of the function will be substituted in place of the
|
||||
The output (return value) of the function will be substituted in place of the
|
||||
function tag in the template (<function>fetch</function> function, for
|
||||
example). Alternatively, the function can simply perform some other
|
||||
task without any output (<function>assign</function> function).
|
||||
@@ -2258,7 +2356,7 @@ function smarty_function_eightball($params, &$smarty)
|
||||
'Maybe in your reality');
|
||||
|
||||
$result = array_rand($answers);
|
||||
echo $answers[$result];
|
||||
return $answers[$result];
|
||||
}
|
||||
?></programlisting>
|
||||
</example>
|
||||
|
||||
Reference in New Issue
Block a user