diff --git a/docs/designers.sgml b/docs/designers.sgml
index e812b6ea..080c864e 100644
--- a/docs/designers.sgml
+++ b/docs/designers.sgml
@@ -250,8 +250,12 @@ email: zaphod@slartibartfast.com<br>
Variables loaded from config files
- Variables that are loaded from the config files are referenced by enclosing
- them within hash marks (#).
+ Variables that are loaded from the config files are referenced by
+ enclosing them within hash marks (#), or with the smarty variable
+ $smarty.config.
+ The second syntax is useful for embedding into quoted attribute
+ values.
@@ -281,7 +285,24 @@ index.tpl:
</body>
</html>
-OUTPUT:
+index.tpl: (alternate syntax)
+
+{config_load file="foo.conf"}
+<html>
+<title>{$smarty.config.pageTitle}</title>
+<body bgcolor="{$smarty.config.bodyBgColor}">
+<table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
+<tr bgcolor="{$smarty.config.rowBgColor}">
+ <td>First</td>
+ <td>Last</td>
+ <td>Address</td>
+</tr>
+</table>
+</body>
+</html>
+
+
+OUTPUT: (same for both examples)
<html>
<title>This is mine</title>
@@ -383,6 +404,15 @@ OUTPUT:
+
+ {$smarty.config}
+
+ {$smarty} variable can be used to refer to loaded config variables.
+ {$smarty.config.foo} is a synonyn for {#foo#}. See the section on
+ config_load for an example.
+
+
+
{$smarty.section}, {$smarty.foreach}
diff --git a/docs/programmers.sgml b/docs/programmers.sgml
index 61ec5839..eef81a2f 100644
--- a/docs/programmers.sgml
+++ b/docs/programmers.sgml
@@ -511,13 +511,30 @@ $smarty->autoload_filters = array('pre' => array('trim', 'stamp'),
string varnamemixed var
+
+ void append
+ string varname
+ mixed var
+ boolean merge
+
This is used to append an element to an assigned array. If you append
to a string value, it is converted to an array value and then
appended to. You can explicitly pass name/value pairs, or associative
- arrays containing the name/value pairs.
+ arrays containing the name/value pairs. If you pass the optional third
+ parameter of true, the value will be merged with the current array
+ instead of appended.
+
+ Technical Note
+
+ The merge parameter respects array keys, so if you merge two
+ numerically indexed arrays, they may overwrite each other or result in
+ non-sequential keys. This is unlike the array_merge() function of PHP
+ which wipes out numerical keys and renumbers them.
+
+ append
@@ -537,10 +554,18 @@ $smarty->append(array("city" => "Lincoln","state" => "Nebraska"));string varnamemixed var
+
+ void append_by_ref
+ string varname
+ mixed var
+ boolean merge
+
This is used to append values to the templates by reference instead of
- making a copy. See the PHP manual on variable referencing for an explanation.
+ making a copy. See the PHP manual on variable referencing for an
+ explanation. If you pass the optional third parameter of true, the value
+ will be merged with the current array instead of appended.
Technical Note
@@ -553,6 +578,15 @@ $smarty->append(array("city" => "Lincoln","state" => "Nebraska"));
+
+ Technical Note
+
+ The merge parameter respects array keys, so if you merge two
+ numerically indexed arrays, they may overwrite each other or result in
+ non-sequential keys. This is unlike the array_merge() function of PHP
+ which wipes out numerical keys and renumbers them.
+
+ append_by_ref
@@ -936,6 +970,56 @@ $output = $smarty->fetch("index.tpl");
// do something with $output here
echo $output;
+
+
+
+ get_config_vars
+
+
+ array get_config_vars
+ string varname
+
+
+
+ This returns the given loaded config variable value. If no parameter
+ is given, an array of all loaded config variables is returned.
+
+
+get_config_vars
+
+// get loaded config template var 'foo'
+$foo = $smarty->get_config_vars('foo');
+
+// get all loaded config template vars
+$config_vars = $smarty->get_config_vars();
+
+// take a look at them
+print_r($config_vars);
+
+
+
+ get_registered_object
+
+
+ array get_registered_object
+ string object_name
+
+
+
+ This returns a reference to a registered object. This is useful
+ from within a custom function when you need direct access to a
+ registered object.
+
+
+get_registered_object
+
+function smarty_block_foo($params, &$smarty) {
+ if (isset[$params['object']]) {
+ // get reference to registered object
+ $obj_ref =& $smarty->&get_registered_object($params['object']);
+ // use $obj_ref is now a reference to the object
+ }
+}
@@ -943,20 +1027,24 @@ echo $output;
array get_template_vars
-
+ string varname
- This gets an array of the currently assigned template vars.
+ This returns the given assigned variable value. If no parameter
+ is given, an array of all assigned variables is returned.
get_template_vars
+// get assigned template var 'foo'
+$foo = $smarty->get_template_vars('foo');
+
// get all assigned template vars
$tpl_vars = $smarty->get_template_vars();
// take a look at them
-var_dump($tpl_vars);
+print_r($tpl_vars);
diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php
index 8ccc11ed..3c38dfc8 100644
--- a/libs/Smarty_Compiler.class.php
+++ b/libs/Smarty_Compiler.class.php
@@ -1449,11 +1449,11 @@ class Smarty_Compiler extends Smarty {
function _expand_quoted_text($var_expr)
{
// if contains unescaped $, expand it
- if(preg_match_all('%(?_var_bracket_regexp . ')*)%', $var_expr, $match)) {
+ if(preg_match_all('%(?_var_bracket_regexp . ')*)\`?%', $var_expr, $match)) {
rsort($match[0]);
reset($match[0]);
foreach($match[0] as $var) {
- $var_expr = str_replace ($var, '".' . $this->_parse_var($var) . '."', $var_expr);
+ $var_expr = str_replace ($var, '".' . $this->_parse_var(str_replace('`','',$var)) . '."', $var_expr);
}
return preg_replace('!\.""|""\.!', '', $var_expr);
} else {
@@ -1677,73 +1677,52 @@ class Smarty_Compiler extends Smarty {
function _compile_smarty_ref(&$indexes)
{
/* Extract the reference name. */
- $ref = substr($indexes[0], 1);
+ $_ref = substr($indexes[0], 1);
- switch ($ref) {
+ foreach($indexes as $_index) {
+ if ($_index{0} != '.') {
+ $this->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
+ }
+ }
+
+ switch ($_ref) {
case 'now':
$compiled_ref = 'time()';
- if (count($indexes) > 1) {
- $this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
- }
+ $_max_index = 1;
break;
case 'foreach':
case 'section':
- if ($indexes[1]{0} != '.') {
- $this->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
- }
- $name = substr($indexes[1], 1);
array_shift($indexes);
- if ($ref == 'foreach')
- $compiled_ref = "\$this->_foreach['$name']";
+ $_var = $this->_parse_var_props(substr($indexes[0], 1));
+ if ($_ref == 'foreach')
+ $compiled_ref = "\$this->_foreach[$_var]";
else
- $compiled_ref = "\$this->_sections['$name']";
+ $compiled_ref = "\$this->_sections[$_var]";
break;
case 'get':
- array_shift($indexes);
$compiled_ref = "\$GLOBALS['HTTP_GET_VARS']";
- if ($name = substr($indexes[0], 1))
- $compiled_ref .= "['$name']";
break;
case 'post':
- array_shift($indexes);
- $name = substr($indexes[0], 1);
$compiled_ref = "\$GLOBALS['HTTP_POST_VARS']";
- if ($name = substr($indexes[0], 1))
- $compiled_ref .= "['$name']";
break;
case 'cookies':
- array_shift($indexes);
- $name = substr($indexes[0], 1);
$compiled_ref = "\$GLOBALS['HTTP_COOKIE_VARS']";
- if ($name = substr($indexes[0], 1))
- $compiled_ref .= "['$name']";
break;
case 'env':
- array_shift($indexes);
$compiled_ref = "\$GLOBALS['HTTP_ENV_VARS']";
- if ($name = substr($indexes[0], 1))
- $compiled_ref .= "['$name']";
break;
case 'server':
- array_shift($indexes);
- $name = substr($indexes[0], 1);
$compiled_ref = "\$GLOBALS['HTTP_SERVER_VARS']";
- if ($name = substr($indexes[0], 1))
- $compiled_ref .= "['$name']";
break;
case 'session':
- array_shift($indexes);
- $name = substr($indexes[0], 1);
$compiled_ref = "\$GLOBALS['HTTP_SESSION_VARS']";
- if ($name = substr($indexes[0], 1))
- $compiled_ref .= "['$name']";
break;
/*
@@ -1759,26 +1738,24 @@ class Smarty_Compiler extends Smarty {
case 'template':
$compiled_ref = "'$this->_current_file'";
- if (count($indexes) > 1) {
- $this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
- }
+ $_max_index = 1;
break;
case 'version':
$compiled_ref = "'$this->_version'";
+ $_max_index = 1;
break;
case 'const':
array_shift($indexes);
- $compiled_ref = '(defined("' . substr($indexes[0],1) . '") ? ' . substr($indexes[0],1) . ' : null)';
+ $_val = $this->_parse_var_props(substr($indexes[0],1));
+ $compiled_ref = "(defined($_val) ? $_val : null)";
+ $_max_index = 1;
break;
case 'config':
- array_shift($indexes);
- $name = substr($indexes[0], 1);
$compiled_ref = "\$this->_config[0]['vars']";
- if ($name = substr($indexes[0], 1))
- $compiled_ref .= "['$name']";
+ $_max_index = 2;
break;
default:
@@ -1786,6 +1763,10 @@ class Smarty_Compiler extends Smarty {
break;
}
+ if (isset($_max_index) && count($indexes) > $_max_index) {
+ $this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
+ }
+
array_shift($indexes);
return $compiled_ref;
}