mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
- new feature/bugfix {foreach}{section} add 'properties' attribute to force compilation of loop properties
see NEW_FEATURES.txt https://github.com/smarty-php/smarty/issues/189
This commit is contained in:
@@ -4,6 +4,28 @@ This file contains a brief description of new features which have been added to
|
|||||||
|
|
||||||
Smarty 3.1.30
|
Smarty 3.1.30
|
||||||
|
|
||||||
|
Loop optimization {foreach} and {section}
|
||||||
|
=========================================
|
||||||
|
Smarty does optimize the {foreach} and {section} loops by removing code for not needed loop
|
||||||
|
properties.
|
||||||
|
The compiler collects needed properties by scanning the current template for $item@property,
|
||||||
|
$smarty.foreach.name.property and $smarty.section.name.property.
|
||||||
|
The compiler does not know if additional properties will be needed outside the current template scope.
|
||||||
|
Additional properties can be generated by adding them with the property attribute.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
index.tpl
|
||||||
|
{foreach $from as $item properties=[iteration, index]}
|
||||||
|
{include 'sub.tpl'}
|
||||||
|
{$item.total}
|
||||||
|
{/foreach}
|
||||||
|
|
||||||
|
sub.tpl
|
||||||
|
{$item.index} {$item.iteration} {$item.total}
|
||||||
|
|
||||||
|
In above example code for the 'total' property is automatically generated as $item.total is used in
|
||||||
|
index.tpl. Code for 'iteration' and 'index' must be added with properties=[iteration, index].
|
||||||
|
|
||||||
New tag {make_nocache}
|
New tag {make_nocache}
|
||||||
======================
|
======================
|
||||||
Syntax: {make_nocache $foo}
|
Syntax: {make_nocache $foo}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
===== 3.1.30-dev ===== (xx.xx.xx)
|
===== 3.1.30-dev ===== (xx.xx.xx)
|
||||||
20.02.2016
|
20.02.2016
|
||||||
- bugfix {strip} must keep space between hmtl tags. Broken by changes of 10.2.2016 https://github.com/smarty-php/smarty/issues/184
|
- bugfix {strip} must keep space between hmtl tags. Broken by changes of 10.2.2016 https://github.com/smarty-php/smarty/issues/184
|
||||||
|
- new feature/bugfix {foreach}{section} add 'properties' attribute to force compilation of loop properties
|
||||||
|
see NEW_FEATURES.txt https://github.com/smarty-php/smarty/issues/189
|
||||||
|
|
||||||
19.02.2016
|
19.02.2016
|
||||||
- revert output buffer flushing on display, echo content again because possible problems when PHP files had
|
- revert output buffer flushing on display, echo content again because possible problems when PHP files had
|
||||||
characters (newline} after ?> at file end https://github.com/smarty-php/smarty/issues/187
|
characters (newline} after ?> at file end https://github.com/smarty-php/smarty/issues/187
|
||||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.30-dev/46';
|
const SMARTY_VERSION = '3.1.30-dev/47';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -30,7 +30,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
|||||||
* @var array
|
* @var array
|
||||||
* @see Smarty_Internal_CompileBase
|
* @see Smarty_Internal_CompileBase
|
||||||
*/
|
*/
|
||||||
public $optional_attributes = array('name', 'key');
|
public $optional_attributes = array('name', 'key', 'properties');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attribute definition: Overwrites base class.
|
* Attribute definition: Overwrites base class.
|
||||||
@@ -137,6 +137,24 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
|
|||||||
if (!empty($this->matchResults[ 'named' ])) {
|
if (!empty($this->matchResults[ 'named' ])) {
|
||||||
$namedAttr = $this->matchResults[ 'named' ];
|
$namedAttr = $this->matchResults[ 'named' ];
|
||||||
}
|
}
|
||||||
|
if (isset($_attr[ 'properties' ]) && preg_match_all("/['](.*?)[']/", $_attr[ 'properties' ], $match)) {
|
||||||
|
foreach ($match[ 1 ] as $prop) {
|
||||||
|
if (in_array($prop, $this->itemProperties)) {
|
||||||
|
$itemAttr[ $prop ] = true;
|
||||||
|
} else {
|
||||||
|
$compiler->trigger_template_error("Invalid property '{$prop}'", null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->isNamed) {
|
||||||
|
foreach ($match[ 1 ] as $prop) {
|
||||||
|
if (in_array($prop, $this->nameProperties)) {
|
||||||
|
$nameAttr[ $prop ] = true;
|
||||||
|
} else {
|
||||||
|
$compiler->trigger_template_error("Invalid property '{$prop}'", null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (isset($itemAttr[ 'first' ])) {
|
if (isset($itemAttr[ 'first' ])) {
|
||||||
$itemAttr[ 'index' ] = true;
|
$itemAttr[ 'index' ] = true;
|
||||||
}
|
}
|
||||||
|
@@ -38,7 +38,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
|||||||
* @var array
|
* @var array
|
||||||
* @see Smarty_Internal_CompileBase
|
* @see Smarty_Internal_CompileBase
|
||||||
*/
|
*/
|
||||||
public $optional_attributes = array('start', 'step', 'max', 'show');
|
public $optional_attributes = array('start', 'step', 'max', 'show', 'properties');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* counter
|
* counter
|
||||||
@@ -119,6 +119,15 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
|
|||||||
if (!empty($this->matchResults[ 'named' ])) {
|
if (!empty($this->matchResults[ 'named' ])) {
|
||||||
$namedAttr = $this->matchResults[ 'named' ];
|
$namedAttr = $this->matchResults[ 'named' ];
|
||||||
}
|
}
|
||||||
|
if (isset($_attr[ 'properties' ]) && preg_match_all("/['](.*?)[']/", $_attr[ 'properties' ], $match)) {
|
||||||
|
foreach ($match[ 1 ] as $prop) {
|
||||||
|
if (in_array($prop, $this->nameProperties)) {
|
||||||
|
$namedAttr[ $prop ] = true;
|
||||||
|
} else {
|
||||||
|
$compiler->trigger_template_error("Invalid property '{$prop}'", null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$namedAttr[ 'index' ] = true;
|
$namedAttr[ 'index' ] = true;
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
foreach ($_attr as $attr_name => $attr_value) {
|
foreach ($_attr as $attr_name => $attr_value) {
|
||||||
|
Reference in New Issue
Block a user