Home » HTML » HTML_Template_Flexy » Bug #8008
flexy:include should accept variables
Details
| Request #8008 | flexy:include should accept variables |
|---|---|
| Submitted | 2006-06-26 21:00 UTC |
| From | tobias dot eberle at gmx dot de |
| Assigned | alan_k |
| Status | Closed |
| Package | HTML_Template_Flexy |
| PHP Version | Irrelevant |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2006-06-26 21:00 UTC] tobias dot eberle at gmx dot de
Description:
------------
Hello,
until now flexy allows only static includes:
<flexy:include src="subpage.html" />
It would be nice if one can use variables instead:
<flexy:include src="{subpage}" />
Thanks a lot!
Bye, Tobias
[2006-06-28 19:16 UTC] tobias dot eberle at gmx dot de
Hello,
here is my patch. Unfortunately it does not support methods yet. I didn't find a correspondig toMethod() method. I will add it if someone gives me a hint.
Bye, Tobias
*** orig/HTML/Template/Flexy/Compiler/Flexy/Flexy.php Tue Jun 27 22:29:50 2006
--- mod/HTML/Template/Flexy/Compiler/Flexy/Flexy.php Wed Jun 28 21:10:59 2006
***************
*** 114,119 ****
--- 114,121 ----
/**
* include handler
* <flexy:include src="test.html">
+ * <flexy:include src="{test}">
+ * <flexy:include src="{test}.html">
*
* @see parent::toString()
*/
***************
*** 123,133 ****
// we ignore modifier pre/suffix
!
!
! $arg = $element->getAttribute('SRC');
! if (!$arg) {
! return $this->compiler->appendHTML("<B>Flexy:Include without a src=filename</B>");
}
// ideally it would be nice to embed the results of one template into another.
// however that would involve some complex test which would have to stat
--- 125,174 ----
// we ignore modifier pre/suffix
! if (!isset($element->ucAttributes['SRC'])) {
! return $this->compiler->appendHTML("<B>Flexy:Include without a src=filename (Line: {$element->line})</B>");
! }
! $arg = $element->ucAttributes['SRC'];
!
! // it's a string so its easy to handle
! if (is_string($arg)) {
! if ($arg == '""') {
! return $this->compiler->appendHTML("<B>Flexy:Include src attribute is empty. (Line: {$element->line})</B>");
! }
! $arg = "'{$element->getAttribute('SRC')}'";
! }
! else {
! // it's an array -> strings and variables possible
! if (is_array($arg)) {
! $string = '"';
! foreach($arg as $item) {
! //it's a string
! if (is_string($item)) {
! if ($item != '' && $item != '"' && $item != '""' &&
! $item != "''") {
! $string .= $item;
! }
! }
! else {
! //it's a variable
! if (is_a($item, 'HTML_Template_Flexy_Token_Var')) {
! $value = $item->toVar($item->value);
! if (is_a($value, 'PEAR_Error')) {
! return $value;
! }
! $string .= "{{$value}}";
! }
! }
! }
! $arg = $string . '"';
! }
! else {
! //something unexspected
! return HTML_Template_Flexy::raiseError(
! ' Flexy:Include SRC needs a string or variable/method as value. '.
! " Error on Line {$element->line} <{$element->tag}>",
! null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
! }
}
// ideally it would be nice to embed the results of one template into another.
// however that would involve some complex test which would have to stat
***************
*** 136,142 ****
// output... include $this->options['compiled_templates'] . $arg . $this->options['locale'] . '.php'
return $this->compiler->appendPHP( "\n".
"\$x = new HTML_Template_Flexy(\$this->options);\n".
! "\$x->compile('{$arg}');\n".
"\$_t = function_exists('clone') ? clone(\$t) : \$t;\n".
"foreach(get_defined_vars() as \$k=>\$v) {\n" .
" if (\$k != 't') { \$_t->\$k = \$v; }\n" .
--- 177,183 ----
// output... include $this->options['compiled_templates'] . $arg . $this->options['locale'] . '.php'
return $this->compiler->appendPHP( "\n".
"\$x = new HTML_Template_Flexy(\$this->options);\n".
! "\$x->compile({$arg});\n".
"\$_t = function_exists('clone') ? clone(\$t) : \$t;\n".
"foreach(get_defined_vars() as \$k=>\$v) {\n" .
" if (\$k != 't') { \$_t->\$k = \$v; }\n" .
***************
*** 219,222 ****
}
!
\ No newline at end of file
--- 260,263 ----
}
!
[2006-11-29 23:21 UTC] skye at F4 dot ca
Has this feature been integrated into stable yet? It would be very useful for us.