Added support for passing variables to included files.

This commit is contained in:
andrey
2000-12-21 17:19:41 +00:00
parent 602f9a0f44
commit 7c0b61d7a7
4 changed files with 46 additions and 6 deletions

View File

@@ -528,8 +528,28 @@ class Smarty
/* TODO syntax error: missing 'file' attribute */ /* TODO syntax error: missing 'file' attribute */
} else } else
$attrs['file'] = $this->_dequote($attrs['file']); $attrs['file'] = $this->_dequote($attrs['file']);
return '<?php include "'.$this->template_dir.$this->compile_dir_ext.'/'.$attrs['file'].'"; ?>'; if (count($attrs) > 1) {
$include_func_name = uniqid("_include_");
$include_file_name = $this->template_dir.$this->compile_dir_ext.'/'.$attrs['file'];
foreach ($attrs as $arg_name => $arg_value) {
if ($arg_name == 'file') continue;
if (is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false';
$arg_list[] = "'$arg_name' => $arg_value";
}
return "<?php\n" .
"function $include_func_name(\$file_name, \$include_vars)\n" .
"{\n" .
" extract(\$GLOBALS);\n" .
" extract(\$include_vars);\n" .
" include \"\$file_name\";\n" .
"}\n" .
"$include_func_name(\"$include_file_name\", array(".implode(',', (array)$arg_list)."));\n?>\n";
} else
return '<?php include "'.$this->template_dir.$this->compile_dir_ext.'/'.$attrs['file'].'"; ?>';
} }
function _compile_section_start($tag_args) function _compile_section_start($tag_args)

View File

@@ -1,3 +1,3 @@
<HTML> <HTML>
<BODY> <BODY>
<TITLE>Monte's title</TITLE> <TITLE>{$title} - {$section}</TITLE>

View File

@@ -528,8 +528,28 @@ class Smarty
/* TODO syntax error: missing 'file' attribute */ /* TODO syntax error: missing 'file' attribute */
} else } else
$attrs['file'] = $this->_dequote($attrs['file']); $attrs['file'] = $this->_dequote($attrs['file']);
return '<?php include "'.$this->template_dir.$this->compile_dir_ext.'/'.$attrs['file'].'"; ?>'; if (count($attrs) > 1) {
$include_func_name = uniqid("_include_");
$include_file_name = $this->template_dir.$this->compile_dir_ext.'/'.$attrs['file'];
foreach ($attrs as $arg_name => $arg_value) {
if ($arg_name == 'file') continue;
if (is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false';
$arg_list[] = "'$arg_name' => $arg_value";
}
return "<?php\n" .
"function $include_func_name(\$file_name, \$include_vars)\n" .
"{\n" .
" extract(\$GLOBALS);\n" .
" extract(\$include_vars);\n" .
" include \"\$file_name\";\n" .
"}\n" .
"$include_func_name(\"$include_file_name\", array(".implode(',', (array)$arg_list)."));\n?>\n";
} else
return '<?php include "'.$this->template_dir.$this->compile_dir_ext.'/'.$attrs['file'].'"; ?>';
} }
function _compile_section_start($tag_args) function _compile_section_start($tag_args)

View File

@@ -1,3 +1,3 @@
<HTML> <HTML>
<BODY> <BODY>
<TITLE>Monte's title</TITLE> <TITLE>{$title} - {$section}</TITLE>