mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 09:54:27 +02:00
update dates versions
This commit is contained in:
7
NEWS
7
NEWS
@@ -1,8 +1,11 @@
|
||||
- updated Smarty to use absolute paths when requiring/including Smarty
|
||||
components. (Andrei, John Lim)
|
||||
- fix LOCK_EX logic once and for all (not used under windows) (Monte)
|
||||
- updated Smarty to use absolute paths when requiring/including Smarty
|
||||
components. (Andrei, John Lim)
|
||||
|
||||
Version 1.4.0
|
||||
-------------
|
||||
- added {capture}{/capture} function, documented (Monte)
|
||||
- added {counter} function, documented (Monte)
|
||||
- fixed indexing by section properties with the new syntax. (Andrei)
|
||||
|
||||
Version 1.4.0b2
|
||||
|
@@ -5,15 +5,29 @@ IMPORTANT NOTICE
|
||||
|
||||
Smarty now has a new syntax for accessing elements within section loops. The
|
||||
new syntax is easier to use and nicely handles data structures of any
|
||||
complexity. Consequently, this breaks the old syntax. To fix your current
|
||||
templates, we have provided a script that will adjust the syntax for you.
|
||||
Located in misc/fix_vars.php, run this script from the the command line, giving
|
||||
each template as an argument. Be sure to use absolute pathnames, or pathnames
|
||||
relative to the executing script. Probably the easiest way to do this is to
|
||||
copy the fix_vars.php script into your template directory and run 'php -q
|
||||
fix_vars.php *.tpl' Be sure you have proper write permission, and backup your
|
||||
scripts first to be safe! The examples in the 1.4.0 documentation have been
|
||||
updated to reflect the changes.
|
||||
complexity. Consequently, this breaks the old syntax.
|
||||
|
||||
Here is an example of the syntax change:
|
||||
|
||||
old syntax:
|
||||
{$sec1/sec2/sec3/customer.phone}
|
||||
|
||||
new syntax:
|
||||
{$customer[$sec1][$sec2][$sec3].phone}
|
||||
|
||||
The section names used to come first, followed by the variable name. Now the
|
||||
variable name always comes first, followed by the section names in brackets.
|
||||
You can access variable indexes anywhere, depending on how you passed the
|
||||
variables in.
|
||||
|
||||
To fix your current templates, we have provided a script that will adjust the
|
||||
syntax for you. Located in misc/fix_vars.php, run this script from the the
|
||||
command line, giving each template as an argument. Be sure to use absolute
|
||||
pathnames, or pathnames relative to the executing script. Probably the easiest
|
||||
way to do this is to copy the fix_vars.php script into your template directory
|
||||
and run 'php -q fix_vars.php *.tpl' Be sure you have proper write permission,
|
||||
and backup your scripts first to be safe! The examples in the 1.4.0
|
||||
documentation have been updated to reflect the changes.
|
||||
|
||||
cd /path/to/templates
|
||||
cp /path/to/fix_vars.php .
|
||||
@@ -81,7 +95,10 @@ symbol and specifying the property name after it, e.g. $foo->bar.
|
||||
|
||||
{php}{/php} tags were added to embed php into the templates. Not normally
|
||||
needed, but some circumstances may call for it. Check out the "componentized
|
||||
templates" tip in the documentation for an example of needed usage.
|
||||
templates" tip in the documentation for an example.
|
||||
|
||||
{capture}{/capture} and {counter} functions were added. See the documentation
|
||||
for a complete description and examples.
|
||||
|
||||
UPGRADE NOTES
|
||||
|
||||
|
@@ -514,6 +514,54 @@ function smarty_mod_count_paragraphs($string,$include_spaces=false) {
|
||||
return count( preg_split("/[\r\n]+/",$string) );
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: smarty_func_counter
|
||||
Purpose: print out a counter value
|
||||
\*======================================================================*/
|
||||
function smarty_func_counter() {
|
||||
|
||||
static $count = array();
|
||||
static $skipval = array();
|
||||
static $dir = array();
|
||||
static $id = "default";
|
||||
static $printval = array();
|
||||
|
||||
extract(func_get_arg(0));
|
||||
|
||||
if(!isset($id))
|
||||
$id = "default";
|
||||
|
||||
if(isset($start))
|
||||
$count[$id] = $start;
|
||||
elseif(!isset($count[$id]))
|
||||
$count[$id]=1;
|
||||
|
||||
if(!isset($print))
|
||||
$printval[$id]=true;
|
||||
else
|
||||
$printval[$id]=$print;
|
||||
|
||||
if($printval[$id])
|
||||
echo $count[$id];
|
||||
|
||||
if(isset($skip))
|
||||
$skipval[$id] = $skip;
|
||||
elseif(!isset($skipval))
|
||||
$skipval[$id] = 1;
|
||||
|
||||
if(isset($direction))
|
||||
$dir[$id] = $direction;
|
||||
elseif(!isset($dir[$id]))
|
||||
$dir[$id] = "up";
|
||||
|
||||
if($dir[$id] == "down")
|
||||
$count[$id] -= $skipval[$id];
|
||||
else
|
||||
$count[$id] += $skipval[$id];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
||||
|
@@ -109,7 +109,8 @@ class Smarty
|
||||
'html_select_date' => 'smarty_func_html_select_date',
|
||||
'html_select_time' => 'smarty_func_html_select_time',
|
||||
'math' => 'smarty_func_math',
|
||||
'fetch' => 'smarty_func_fetch'
|
||||
'fetch' => 'smarty_func_fetch',
|
||||
'counter' => 'smarty_func_counter'
|
||||
);
|
||||
|
||||
var $custom_mods = array( 'lower' => 'strtolower',
|
||||
@@ -645,7 +646,7 @@ class Smarty
|
||||
$funcname($resource_name, $template_source, $template_timestamp);
|
||||
return true;
|
||||
} else {
|
||||
$this->_trigger_error_msg("function: resource function \"$funcname\" does not exist for resource type: \"$resource_type\".");
|
||||
$this->_trigger_error_msg("resource function: \"$funcname\" does not exist for resource type: \"$resource_type\".");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -776,7 +777,11 @@ class Smarty
|
||||
$this->_trigger_error_msg("problem writing '$filename.'");
|
||||
return false;
|
||||
}
|
||||
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
|
||||
|
||||
// flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?),
|
||||
// so we'll not use it at all in windows.
|
||||
|
||||
if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd, LOCK_EX)) ) {
|
||||
fwrite( $fd, $contents );
|
||||
fclose($fd);
|
||||
chmod($filename,0644);
|
||||
@@ -785,7 +790,6 @@ class Smarty
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _clear_tpl_cache_dir
|
||||
Purpose: Clear the specified template cache
|
||||
|
126
docs.sgml
126
docs.sgml
@@ -1225,7 +1225,7 @@ $smarty->display("db:index.tpl");
|
||||
</sect2>
|
||||
</sect1>
|
||||
<sect1 id="section.template.prefilters">
|
||||
<title>Template Preilters</title>
|
||||
<title>Template Prefilters</title>
|
||||
<para>
|
||||
Template prefilters are PHP functions that your templates are ran through
|
||||
before they are compiled. This is good for preprocessing your templates
|
||||
@@ -1558,6 +1558,41 @@ Intro = """This is a value that spans more
|
||||
are integral to the template language. You cannot create custom
|
||||
functions with the same names, nor can you modify built-in functions.
|
||||
</para>
|
||||
<sect2 id="builtin.function.capture">
|
||||
<title>capture</title>
|
||||
<para>
|
||||
capture is used to collect the output of the template into a
|
||||
variable instead of displaying it. Any content between {capture} and
|
||||
{/capture} is collected into the special $return variable, which can
|
||||
be used in the template from that point on. All {capture} commands
|
||||
must be paired with {/capture}. You can nest capture commands, but
|
||||
be aware that each iteration will overwrite the last value of
|
||||
$return. capture was added to Smarty 1.4.0.
|
||||
</para>
|
||||
<para>
|
||||
TECHNICAL NOTE: Be careful when capturing {insert} output. If you
|
||||
have caching turned on and you have {insert} commands that you
|
||||
expect to run within cached content, do not capture this content.
|
||||
</para>
|
||||
<example>
|
||||
<title>capturing template content</title>
|
||||
<programlisting>
|
||||
|
||||
{* we don't want to print a table row unless content is displayed *}
|
||||
{capture}
|
||||
{include file="get_banner.tpl"}
|
||||
{/capture}
|
||||
{if $return ne ""}
|
||||
<tr>
|
||||
<td>
|
||||
{$return}
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="builtin.functions.configload">
|
||||
<title>config_load</title>
|
||||
<informaltable frame=all>
|
||||
@@ -1922,7 +1957,7 @@ OUTPUT:
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2 id="builtin.funciton.literal">
|
||||
<sect2 id="builtin.function.literal">
|
||||
<title>literal</title>
|
||||
<para>
|
||||
Literal tags allow a block of data to be taken literally,
|
||||
@@ -2497,6 +2532,93 @@ OUTPUT:
|
||||
Custom functions in Smarty work much the same as the built-in functions
|
||||
syntactically.
|
||||
</para>
|
||||
<sect2>
|
||||
<title>counter</title>
|
||||
<informaltable frame=all>
|
||||
<tgroup cols=3>
|
||||
<colspec colname=param>
|
||||
<colspec colname=type>
|
||||
<colspec colname=required>
|
||||
<colspec colname=default>
|
||||
<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>id</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>default</emphasis></entry>
|
||||
<entry>The id of the counter</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>start</entry>
|
||||
<entry>number</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>1</emphasis></entry>
|
||||
<entry>The initial number to start counting from</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>skip</entry>
|
||||
<entry>number</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>1</emphasis></entry>
|
||||
<entry>The interval to count by</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>direction</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>up</emphasis></entry>
|
||||
<entry>the direction to count (up/down)</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>print</entry>
|
||||
<entry>boolean</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>false</emphasis></entry>
|
||||
<entry>Whether or not to print the value</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
<para>
|
||||
counter is used to print out a count. counter will remember the
|
||||
count on each iteration. You can adjust the number, the interval
|
||||
and the direction of the count, as well as determine whether or not
|
||||
to print the value. You can run multiple counters concurrently by
|
||||
supplying a unique id for each one. If you do not supply an id, the
|
||||
default id will be used. counter was added to Smarty 1.4.0.
|
||||
</para>
|
||||
<example>
|
||||
<title>counter</title>
|
||||
<programlisting>
|
||||
|
||||
{* initialize the count *}
|
||||
{counter start=0 skip=2 print=false}
|
||||
|
||||
{counter}<br>
|
||||
{counter}<br>
|
||||
{counter}<br>
|
||||
{counter}<br>
|
||||
|
||||
OUTPUT:
|
||||
|
||||
2<br>
|
||||
4<br>
|
||||
6<br>
|
||||
8<br>
|
||||
|
||||
</programlisting>
|
||||
</example>
|
||||
</sect2>
|
||||
<sect2>
|
||||
<title>fetch</title>
|
||||
<informaltable frame=all>
|
||||
|
@@ -109,7 +109,8 @@ class Smarty
|
||||
'html_select_date' => 'smarty_func_html_select_date',
|
||||
'html_select_time' => 'smarty_func_html_select_time',
|
||||
'math' => 'smarty_func_math',
|
||||
'fetch' => 'smarty_func_fetch'
|
||||
'fetch' => 'smarty_func_fetch',
|
||||
'counter' => 'smarty_func_counter'
|
||||
);
|
||||
|
||||
var $custom_mods = array( 'lower' => 'strtolower',
|
||||
@@ -645,7 +646,7 @@ class Smarty
|
||||
$funcname($resource_name, $template_source, $template_timestamp);
|
||||
return true;
|
||||
} else {
|
||||
$this->_trigger_error_msg("function: resource function \"$funcname\" does not exist for resource type: \"$resource_type\".");
|
||||
$this->_trigger_error_msg("resource function: \"$funcname\" does not exist for resource type: \"$resource_type\".");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -776,7 +777,11 @@ class Smarty
|
||||
$this->_trigger_error_msg("problem writing '$filename.'");
|
||||
return false;
|
||||
}
|
||||
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
|
||||
|
||||
// flock doesn't seem to work on several windows platforms (98, NT4, NT5, ?),
|
||||
// so we'll not use it at all in windows.
|
||||
|
||||
if ( strtoupper(substr(PHP_OS,0,3)) == 'WIN' || (flock($fd, LOCK_EX)) ) {
|
||||
fwrite( $fd, $contents );
|
||||
fclose($fd);
|
||||
chmod($filename,0644);
|
||||
@@ -785,7 +790,6 @@ class Smarty
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _clear_tpl_cache_dir
|
||||
Purpose: Clear the specified template cache
|
||||
|
Reference in New Issue
Block a user