mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
Block functions changes.
This commit is contained in:
4
CREDITS
4
CREDITS
@@ -3,8 +3,8 @@ Monte Ohrt <monte@ispi.net>:
|
||||
concept" implementation, and maintains documentation & code base.
|
||||
|
||||
Andrei Zmievski <andrei@php.net>:
|
||||
Rewrote parser from scratch, developed plugin architecture, and maintains
|
||||
code base.
|
||||
Rewrote parser from scratch, developed plugin architecture, reorganized
|
||||
documentation, and maintains code base.
|
||||
|
||||
Anne Holz <anne@ispi.net>:
|
||||
Provided creative input with respect to web design.
|
||||
|
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
||||
- implemented support for block functions. (Andrei)
|
||||
- made it possible to assign variables in pre/postfilter
|
||||
plugins. (Andrei)
|
||||
|
||||
|
@@ -150,6 +150,7 @@ class Smarty
|
||||
var $_smarty_vars = null; // stores run-time $smarty.* vars
|
||||
var $_sections = array(); // keeps track of sections
|
||||
var $_foreach = array(); // keeps track of foreach blocks
|
||||
var $_tag_stack = array(); // keeps track of tag hierarchy
|
||||
var $_conf_obj = null; // configuration object
|
||||
var $_config = array(); // loaded configuration settings
|
||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||
@@ -275,6 +276,25 @@ class Smarty
|
||||
unset($this->_plugins['function'][$function]);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: register_block
|
||||
Purpose: Registers block function to be used in templates
|
||||
\*======================================================================*/
|
||||
function register_block($block, $block_impl)
|
||||
{
|
||||
$this->_plugins['block'][$block] =
|
||||
array($block_impl, null, null, false);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: unregister_block
|
||||
Purpose: Unregisters block function
|
||||
\*======================================================================*/
|
||||
function unregister_block($block)
|
||||
{
|
||||
unset($this->_plugins['block'][$block]);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: register_compiler_function
|
||||
Purpose: Registers compiler function
|
||||
|
@@ -470,18 +470,18 @@ class Smarty_Compiler extends Smarty {
|
||||
*/
|
||||
$this->_add_plugin('block', $tag_command);
|
||||
|
||||
$arg_list = array();
|
||||
$attrs = $this->_parse_attrs($tag_args);
|
||||
foreach ($attrs as $arg_name => $arg_value) {
|
||||
if (is_bool($arg_value))
|
||||
$arg_value = $arg_value ? 'true' : 'false';
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
|
||||
if ($start_tag) {
|
||||
$output = "<?php \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>";
|
||||
$arg_list = array();
|
||||
$attrs = $this->_parse_attrs($tag_args);
|
||||
foreach ($attrs as $arg_name => $arg_value) {
|
||||
if (is_bool($arg_value))
|
||||
$arg_value = $arg_value ? 'true' : 'false';
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
|
||||
$output = "<?php \$this->_tag_stack[] = array('$tag_command', array(".implode(',', (array)$arg_list).")); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>";
|
||||
} else {
|
||||
$output = "<?php \$this->_block = ob_get_contents(); ob_end_clean(); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this->_block, \$this); ?>";
|
||||
$output = "<?php \$this->_block_content = ob_get_contents(); ob_end_clean(); \$this->_plugins['block']['$tag_command'][0](\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$this->_block_content, \$this); array_pop(\$this->_tag_stack); ?>";
|
||||
}
|
||||
|
||||
return true;
|
||||
|
1
TODO
1
TODO
@@ -4,7 +4,6 @@
|
||||
* support implementations of prefiltes, mods, and others as class methods.
|
||||
* possibly implement default modifiers that apply to variables upon display
|
||||
* think about possibility of supporting something like {$data[foo].$key[bar]}
|
||||
* allow {custom} .. {/custom} style of custom functions
|
||||
* ability to concatenate values/strings together
|
||||
* fix all E_NOTICE warnings
|
||||
* make simple math easier
|
||||
|
@@ -150,6 +150,7 @@ class Smarty
|
||||
var $_smarty_vars = null; // stores run-time $smarty.* vars
|
||||
var $_sections = array(); // keeps track of sections
|
||||
var $_foreach = array(); // keeps track of foreach blocks
|
||||
var $_tag_stack = array(); // keeps track of tag hierarchy
|
||||
var $_conf_obj = null; // configuration object
|
||||
var $_config = array(); // loaded configuration settings
|
||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||
@@ -275,6 +276,25 @@ class Smarty
|
||||
unset($this->_plugins['function'][$function]);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: register_block
|
||||
Purpose: Registers block function to be used in templates
|
||||
\*======================================================================*/
|
||||
function register_block($block, $block_impl)
|
||||
{
|
||||
$this->_plugins['block'][$block] =
|
||||
array($block_impl, null, null, false);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: unregister_block
|
||||
Purpose: Unregisters block function
|
||||
\*======================================================================*/
|
||||
function unregister_block($block)
|
||||
{
|
||||
unset($this->_plugins['block'][$block]);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
Function: register_compiler_function
|
||||
Purpose: Registers compiler function
|
||||
|
@@ -470,18 +470,18 @@ class Smarty_Compiler extends Smarty {
|
||||
*/
|
||||
$this->_add_plugin('block', $tag_command);
|
||||
|
||||
$arg_list = array();
|
||||
$attrs = $this->_parse_attrs($tag_args);
|
||||
foreach ($attrs as $arg_name => $arg_value) {
|
||||
if (is_bool($arg_value))
|
||||
$arg_value = $arg_value ? 'true' : 'false';
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
|
||||
if ($start_tag) {
|
||||
$output = "<?php \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>";
|
||||
$arg_list = array();
|
||||
$attrs = $this->_parse_attrs($tag_args);
|
||||
foreach ($attrs as $arg_name => $arg_value) {
|
||||
if (is_bool($arg_value))
|
||||
$arg_value = $arg_value ? 'true' : 'false';
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
|
||||
$output = "<?php \$this->_tag_stack[] = array('$tag_command', array(".implode(',', (array)$arg_list).")); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>";
|
||||
} else {
|
||||
$output = "<?php \$this->_block = ob_get_contents(); ob_end_clean(); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this->_block, \$this); ?>";
|
||||
$output = "<?php \$this->_block_content = ob_get_contents(); ob_end_clean(); \$this->_plugins['block']['$tag_command'][0](\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$this->_block_content, \$this); array_pop(\$this->_tag_stack); ?>";
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user