mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
added assign to include and php_include
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
||||
- added assign attribute to include and include_php, documented (Monte)
|
||||
- added include_php built-in function. (Monte)
|
||||
- added trusted_dir functionality, documented. (Monte)
|
||||
- consolidated secure_dir tests to one function. (Monte)
|
||||
|
@@ -431,18 +431,22 @@ class Smarty_Compiler extends Smarty {
|
||||
$include_file = $arg_value;
|
||||
continue;
|
||||
}
|
||||
elseif ($arg_name == 'assign') {
|
||||
$assign_var = $arg_value;
|
||||
continue;
|
||||
}
|
||||
if (is_bool($arg_value))
|
||||
$arg_value = $arg_value ? 'true' : 'false';
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
if (!empty($attrs['assign'])) {
|
||||
if (isset($assign_var)) {
|
||||
$return = "<?php ob_start();\n";
|
||||
$return .=
|
||||
"\$_smarty_tpl_vars = \$this->_tpl_vars;\n" .
|
||||
"\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."));\n" .
|
||||
"\$this->_tpl_vars = \$_smarty_tpl_vars;\n" .
|
||||
"unset(\$_smarty_tpl_vars);\n";
|
||||
$return .= "\$this->assign('".$this->_dequote($attrs['assign'])."',ob_get_contents()); ob_end_clean();\n?>";
|
||||
$return .= "\$this->assign('".$this->_dequote($assign_var)."',ob_get_contents()); ob_end_clean();\n?>";
|
||||
} else {
|
||||
$return = "<?php " .
|
||||
"\$_smarty_tpl_vars = \$this->_tpl_vars;\n" .
|
||||
|
26
docs.sgml
26
docs.sgml
@@ -2292,6 +2292,14 @@ pass=foobar
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>The name of the template file to include</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>assign</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>The name of the varible that the output of
|
||||
include will be assigned to</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>[var ...]</entry>
|
||||
<entry>[var type]</entry>
|
||||
@@ -2308,6 +2316,11 @@ pass=foobar
|
||||
available within the included template. The include tag must have
|
||||
the attribute "file", which contains the template resource path.
|
||||
</para>
|
||||
<para>
|
||||
You an optionally pass the assign attribute, which will specify a
|
||||
template variable name that the output of include will be assigned
|
||||
to instead of displayed. This was added to Smarty 1.5.0.
|
||||
</para>
|
||||
<example>
|
||||
<title>function include</title>
|
||||
<programlisting>
|
||||
@@ -2365,6 +2378,14 @@ pass=foobar
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>The name of the php file to include</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>assign</entry>
|
||||
<entry>string</entry>
|
||||
<entry>No</entry>
|
||||
<entry><emphasis>n/a</emphasis></entry>
|
||||
<entry>The name of the varible that the output of
|
||||
include_php will be assigned to</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
@@ -2386,6 +2407,11 @@ pass=foobar
|
||||
before hand.
|
||||
</para>
|
||||
<para>
|
||||
You an optionally pass the assign attribute, which will specify a
|
||||
template variable name that the output of include_php will be
|
||||
assigned to instead of displayed.
|
||||
</para>
|
||||
<para>
|
||||
include_php was added to Smarty 1.5.0.
|
||||
</para>
|
||||
<example>
|
||||
|
@@ -431,18 +431,22 @@ class Smarty_Compiler extends Smarty {
|
||||
$include_file = $arg_value;
|
||||
continue;
|
||||
}
|
||||
elseif ($arg_name == 'assign') {
|
||||
$assign_var = $arg_value;
|
||||
continue;
|
||||
}
|
||||
if (is_bool($arg_value))
|
||||
$arg_value = $arg_value ? 'true' : 'false';
|
||||
$arg_list[] = "'$arg_name' => $arg_value";
|
||||
}
|
||||
if (!empty($attrs['assign'])) {
|
||||
if (isset($assign_var)) {
|
||||
$return = "<?php ob_start();\n";
|
||||
$return .=
|
||||
"\$_smarty_tpl_vars = \$this->_tpl_vars;\n" .
|
||||
"\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."));\n" .
|
||||
"\$this->_tpl_vars = \$_smarty_tpl_vars;\n" .
|
||||
"unset(\$_smarty_tpl_vars);\n";
|
||||
$return .= "\$this->assign('".$this->_dequote($attrs['assign'])."',ob_get_contents()); ob_end_clean();\n?>";
|
||||
$return .= "\$this->assign('".$this->_dequote($assign_var)."',ob_get_contents()); ob_end_clean();\n?>";
|
||||
} else {
|
||||
$return = "<?php " .
|
||||
"\$_smarty_tpl_vars = \$this->_tpl_vars;\n" .
|
||||
|
Reference in New Issue
Block a user