added assign to include and php_include

This commit is contained in:
mohrt
2001-12-05 16:36:58 +00:00
parent b0bb62ff9a
commit 139bba650e
4 changed files with 39 additions and 4 deletions

1
NEWS
View File

@@ -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)

View File

@@ -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" .

View File

@@ -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>

View File

@@ -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" .