- Added $smarty.template variable.

- Fixed {include_php} tag when dynamic values were used for 'file' attribute.
This commit is contained in:
andrei
2002-04-03 16:31:59 +00:00
parent e1f8273788
commit dd56027476
5 changed files with 78 additions and 41 deletions

5
NEWS
View File

@@ -1,3 +1,6 @@
- fixed a problem with using dynamic values for 'file'
attribute of {include_php} tag. (Andrei)
- added $smarty.template variable. (Andrei)
- fixed several plugins that would not work if the plugin - fixed several plugins that would not work if the plugin
directory was not the default one. (Andrei) directory was not the default one. (Andrei)
- implemented support for block functions. (Andrei) - implemented support for block functions. (Andrei)
@@ -339,4 +342,4 @@ Version 1.0
------------ ------------
- initial release - initial release
/* vim: set et tw=64: */ /* vim: set et tw=64 ft=changelog: */

View File

@@ -1008,6 +1008,33 @@ function _generate_debug_output() {
} }
} }
/*======================================================================*\
Function: _smarty_include_php()
Purpose: called for included templates
\*======================================================================*/
function _smarty_include_php($_smarty_include_php_file, $_smarty_assign)
{
$this->_get_php_resource($_smarty_include_php_file, $_smarty_resource_type,
$_smarty_php_resource);
if (!empty($_smarty_assign)) {
ob_start();
if ($_smarty_resource_type == 'file') {
include_once($_smarty_php_resource);
} else {
eval($_smarty_php_resource);
}
$this->assign($_smarty_assign, ob_get_contents());
ob_end_clean();
} else {
if ($_smarty_resource_type == 'file') {
include_once($_smarty_php_resource);
} else {
eval($_smarty_php_resource);
}
}
}
/*======================================================================*\ /*======================================================================*\
Function: _config_load Function: _config_load
Purpose: load configuration values Purpose: load configuration values

View File

@@ -632,27 +632,10 @@ class Smarty_Compiler extends Smarty {
if (empty($attrs['file'])) { if (empty($attrs['file'])) {
$this->_syntax_error("missing 'file' attribute in include_php tag"); $this->_syntax_error("missing 'file' attribute in include_php tag");
} }
$assign_var = $this->_dequote($attrs['assign']);
$this->_get_php_resource($this->_dequote($attrs['file']), return "<?php \$this->_smarty_include_php($attrs[file], '$assign_var'); ?>";
$resource_type, $php_resource);
if (!empty($attrs['assign'])) {
$output = "<?php ob_start();\n";
if ($resource_type == 'file') {
$output .= 'include("' . $php_resource . '");'."\n";
} else {
$output .= $php_resource;
}
$output .= "\$this->assign(" . $attrs['assign'] . ", ob_get_contents()); ob_end_clean();\n?>";
} else {
if ($resource_type == 'file') {
$output = '<?php include("' . $php_resource . '"); ?>';
} else {
$output = '<?php ' . $php_resource . ' ?>';
}
}
return $output;
} }
@@ -1350,6 +1333,13 @@ class Smarty_Compiler extends Smarty {
case 'capture': case 'capture':
return null; return null;
case 'template':
$compiled_ref = "'$this->_current_file'";
if (count($indexes) > 1) {
$this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference');
}
break;
default: default:
$this->_syntax_error('$smarty.' . $ref . ' is an unknown reference'); $this->_syntax_error('$smarty.' . $ref . ' is an unknown reference');
break; break;

View File

@@ -1008,6 +1008,33 @@ function _generate_debug_output() {
} }
} }
/*======================================================================*\
Function: _smarty_include_php()
Purpose: called for included templates
\*======================================================================*/
function _smarty_include_php($_smarty_include_php_file, $_smarty_assign)
{
$this->_get_php_resource($_smarty_include_php_file, $_smarty_resource_type,
$_smarty_php_resource);
if (!empty($_smarty_assign)) {
ob_start();
if ($_smarty_resource_type == 'file') {
include_once($_smarty_php_resource);
} else {
eval($_smarty_php_resource);
}
$this->assign($_smarty_assign, ob_get_contents());
ob_end_clean();
} else {
if ($_smarty_resource_type == 'file') {
include_once($_smarty_php_resource);
} else {
eval($_smarty_php_resource);
}
}
}
/*======================================================================*\ /*======================================================================*\
Function: _config_load Function: _config_load
Purpose: load configuration values Purpose: load configuration values

View File

@@ -632,27 +632,10 @@ class Smarty_Compiler extends Smarty {
if (empty($attrs['file'])) { if (empty($attrs['file'])) {
$this->_syntax_error("missing 'file' attribute in include_php tag"); $this->_syntax_error("missing 'file' attribute in include_php tag");
} }
$assign_var = $this->_dequote($attrs['assign']);
$this->_get_php_resource($this->_dequote($attrs['file']), return "<?php \$this->_smarty_include_php($attrs[file], '$assign_var'); ?>";
$resource_type, $php_resource);
if (!empty($attrs['assign'])) {
$output = "<?php ob_start();\n";
if ($resource_type == 'file') {
$output .= 'include("' . $php_resource . '");'."\n";
} else {
$output .= $php_resource;
}
$output .= "\$this->assign(" . $attrs['assign'] . ", ob_get_contents()); ob_end_clean();\n?>";
} else {
if ($resource_type == 'file') {
$output = '<?php include("' . $php_resource . '"); ?>';
} else {
$output = '<?php ' . $php_resource . ' ?>';
}
}
return $output;
} }
@@ -1350,6 +1333,13 @@ class Smarty_Compiler extends Smarty {
case 'capture': case 'capture':
return null; return null;
case 'template':
$compiled_ref = "'$this->_current_file'";
if (count($indexes) > 1) {
$this->_syntax_error('$smarty' . implode('', $indexes) .' is an invalid reference');
}
break;
default: default:
$this->_syntax_error('$smarty.' . $ref . ' is an unknown reference'); $this->_syntax_error('$smarty.' . $ref . ' is an unknown reference');
break; break;