Home > Archive > PHP Pear > August 2004 > [PEAR] HTTP_Template_Flexy Questions
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
[PEAR] HTTP_Template_Flexy Questions
|
|
| Jamie Wall 2004-08-08, 8:55 pm |
| First: I am really finding Flexy useful!
Second:
I have 2 questions concerning the use of Flexy:
1. Is there a way to use prefix/suffix with form tags? To make it work
for me, I am modifying HTTP_Template_Flexy_Element method
toHtmlNoClose() like:
return "{$prefix}<{$ret->tag}".$ret->attributesToHTML() . '>' .
$ret->childrenToHTML() . $suffix;
2. Is their a way to compile/output a string which contains the template
instead of using a file on disk? I see:
function compile(&$flexy,$string=false)
in HTML_Template_Flexy_Compiler_Standard, but I also want mergeElement
functionality which is in outputObject/bufferedOutputObject which seems
to rely on a template on disk. I have it mostly working, but again I
have to modify/subclass which doesn't seem right.
Thank you in advance.
Jamie Wall
http://www.webpeak.com
1(727)527-3646
--
Jamie Wall
http://www.webpeak.com
1(727)527-3646
| |
| Alan Knowles 2004-08-09, 9:03 am |
| Jamie Wall wrote:
> First: I am really finding Flexy useful!
>
> Second:
>
> I have 2 questions concerning the use of Flexy:
>
> 1. Is there a way to use prefix/suffix with form tags? To make it work
> for me, I am modifying HTTP_Template_Flexy_Element method
> toHtmlNoClose() like:
>
> return "{$prefix}<{$ret->tag}".$ret->attributesToHTML() . '>' .
> $ret->childrenToHTML() . $suffix;
It would involve adding an extra call to the page:
$this->elements['formName']->closeToHtml();
put it as a feature request on the package bug page.. - with code if you
have time..
>
> 2. Is their a way to compile/output a string which contains the template
> instead of using a file on disk? I see:
>
> function compile(&$flexy,$string=false)
>
> in HTML_Template_Flexy_Compiler_Standard, but I also want mergeElement
> functionality which is in outputObject/bufferedOutputObject which seems
> to rely on a template on disk. I have it mostly working, but again I
> have to modify/subclass which doesn't seem right.
>
There is.. :) - although it's not normally recommended as the compiling
stage is not very fast (eg. expect 100% CPU utilization on anything over
100 lines)..
class StringCompiler extends HTML_Template_Flexy {
var $compiledString;
function StringCompiler($opts) {
$opts['compileToString'] = true;
parent::HTML_Template_Flexy($opts);
}
function compile($string) {
$compiler = HTML_Template_Flexy_Compiler::factory($t
his->options);
$this->compiledString = $compiler->compile($x,$string);
}
function outputObject($t,$elements) {
eval($this->compiledString);
}
}
you may want to look at the Flexy Source a bit more to add features, but
the basic stuff should work by doing this..
Regards
Alan
> Thank you in advance.
>
> Jamie Wall
> http://www.webpeak.com
> 1(727)527-3646
>
| |
| Jamie Wall 2004-08-09, 9:03 am |
| Thanks!
Another question:
Is it possible to manipulate a dynamic element which has a variable in it?
Template:
<mybutton id="CustomerButton" value="{customer.id}" flexy:dynamic="yes" />
Element Code:
$elements=$template->getElements();
foreach ($elements as $elementName => $element) {
if ($element->tag=='mybutton') {
$buttonAttributes=array(
'type'=>'button',
'onclick'=>"java script:doSomething()"
);
$elements[$elementName]=new HTML_Template_Flexy_Element("input",
$buttonAttributes);
}
It seems like I can't have any {} in my template for a dynamic element.
Is there a way to have the {customer.id} expanded to its value before
the element code takes place so I end up with:
<input type="button" onclick="java script:soSomething()"
id="CustomerButton" value="26" />
instead of:
<input type="button" onclick="java script:soSomething()"
id="CustomerButton" />
I see:
// general assumption - none of the tools can do much with dynamic
// attributes - eg. stuff with flexy tags in it.
if (!is_string($this->ucAttributes[$key])) {
return false;
}
$v = $this->ucAttributes[$key];
in the getAttribute() function of Tag.php which seems a bit
discouraging. I think if I could have dynamic elements with variable
template code in them, it would be like winning the lottery :-)!
Jamie Wall
http://www.webpeak.com
1(727)527-3646
Alan Knowles wrote:
> Jamie Wall wrote:
>
>
>
> It would involve adding an extra call to the page:
> $this->elements['formName']->closeToHtml();
>
> put it as a feature request on the package bug page.. - with code if
> you have time..
>
>
> There is.. :) - although it's not normally recommended as the
> compiling stage is not very fast (eg. expect 100% CPU utilization on
> anything over 100 lines)..
>
> class StringCompiler extends HTML_Template_Flexy {
> var $compiledString;
> function StringCompiler($opts) {
> $opts['compileToString'] = true;
> parent::HTML_Template_Flexy($opts);
> }
> function compile($string) {
>
> $compiler =
> HTML_Template_Flexy_Compiler::factory($t
his->options);
>
> $this->compiledString = $compiler->compile($x,$string);
> }
> function outputObject($t,$elements) {
> eval($this->compiledString);
> }
> }
> you may want to look at the Flexy Source a bit more to add features,
> but the basic stuff should work by doing this..
>
> Regards
> Alan
>
>
>
>
>
>
>
| |
| Alan Knowles 2004-08-09, 3:56 pm |
| Jamie Wall wrote:
> Thanks!
>
> Another question:
>
> Is it possible to manipulate a dynamic element which has a variable in
> it?
At the moment, they are mutally exclusive : -
use dynamic attributes: - cant use elements
use element : - cant use dynamic attributes..
The problem is that the elements are rendered as
$this->element['name']->toHtml();
and the element have no knowledge of dynamic values.
It could be fixed I guess.. - probably worth filing as a bug.. (although
fixes hapen faster with patches)
it would probably involve having attributes['xxxx'] = array('....',
array('getVar','$t->.....')
and also passing $t to the object, so that it has something to render..
Regards
Alan
[color=darkred]
>
> Template:
> <mybutton id="CustomerButton" value="{customer.id}"
> flexy:dynamic="yes" />
>
> Element Code:
> $elements=$template->getElements();
> foreach ($elements as $elementName => $element) {
> if ($element->tag=='mybutton') {
> $buttonAttributes=array(
> 'type'=>'button',
> 'onclick'=>"java script:doSomething()"
> );
> $elements[$elementName]=new HTML_Template_Flexy_Element("input",
>
> $buttonAttributes);
> }
>
> It seems like I can't have any {} in my template for a dynamic
> element. Is there a way to have the {customer.id} expanded to its
> value before the element code takes place so I end up with:
>
> <input type="button" onclick="java script:soSomething()"
> id="CustomerButton" value="26" />
>
> instead of:
>
> <input type="button" onclick="java script:soSomething()"
> id="CustomerButton" />
>
> I see:
>
> // general assumption - none of the tools can do much with dynamic
> // attributes - eg. stuff with flexy tags in it.
> if (!is_string($this->ucAttributes[$key])) {
> return false;
> }
> $v = $this->ucAttributes[$key];
>
> in the getAttribute() function of Tag.php which seems a bit
> discouraging. I think if I could have dynamic elements with variable
> template code in them, it would be like winning the lottery :-)!
>
>
> Jamie Wall
> http://www.webpeak.com
> 1(727)527-3646
>
>
>
> Alan Knowles wrote:
>
| |
| Jamie Wall 2004-08-09, 3:56 pm |
| Alan Knowles wrote:
> Jamie Wall wrote:
>
>
>
> At the moment, they are mutally exclusive : -
> use dynamic attributes: - cant use elements
> use element : - cant use dynamic attributes..
>
> The problem is that the elements are rendered as
> $this->element['name']->toHtml();
> and the element have no knowledge of dynamic values.
>
> It could be fixed I guess.. - probably worth filing as a bug..
> (although fixes hapen faster with patches)
>
> it would probably involve having attributes['xxxx'] = array('....',
> array('getVar','$t->.....')
> and also passing $t to the object, so that it has something to render..
What class would this work be done in?
Jamie
[color=darkred]
>
> Regards
> Alan
>
>
| |
| Jamie Wall 2004-08-09, 3:56 pm |
| I notice in the comments for toHtmlnoClose:
* Output Open Tag and any children and not Child tag (designed for
use with <form + hidden elements>
Would you explain the hidden elements part? That might solve my problem,
as I am trying to rewrite the form element with hidden elements using
the notion of element->suffix. Maybe, based on this comment, there is
already a way.
Thanks.
Jamie Wall
http://www.webpeak.com
1(727)527-3646
Alan Knowles wrote:
> Jamie Wall wrote:
>
>
>
> It would involve adding an extra call to the page:
> $this->elements['formName']->closeToHtml();
>
> put it as a feature request on the package bug page.. - with code if
> you have time..
>
>
> There is.. :) - although it's not normally recommended as the
> compiling stage is not very fast (eg. expect 100% CPU utilization on
> anything over 100 lines)..
>
> class StringCompiler extends HTML_Template_Flexy {
> var $compiledString;
> function StringCompiler($opts) {
> $opts['compileToString'] = true;
> parent::HTML_Template_Flexy($opts);
> }
> function compile($string) {
>
> $compiler =
> HTML_Template_Flexy_Compiler::factory($t
his->options);
>
> $this->compiledString = $compiler->compile($x,$string);
> }
> function outputObject($t,$elements) {
> eval($this->compiledString);
> }
> }
> you may want to look at the Flexy Source a bit more to add features,
> but the basic stuff should work by doing this..
>
> Regards
> Alan
>
>
>
>
>
>
>
| |
| Alan Knowles 2004-08-09, 8:56 pm |
| you can use
$x['form'] = new HTML_Template_Flexy_Element;
$hidden = new HTML_Template_Flexy_Element('input',arra
y('type'=>'hidden'));
foreach($hiddenValues as $k=>$v) {
$h = clone($hidden);
$h->attributes['name'] = $k;
$h->attributes['value'] = $v;
$x['form']->children[] = $h;
}
Should do that..
Regards
Alan
Jamie Wall wrote:
[color=darkred]
> I notice in the comments for toHtmlnoClose:
>
> * Output Open Tag and any children and not Child tag (designed for
> use with <form + hidden elements>
>
> Would you explain the hidden elements part? That might solve my
> problem, as I am trying to rewrite the form element with hidden
> elements using the notion of element->suffix. Maybe, based on this
> comment, there is already a way.
>
> Thanks.
>
> Jamie Wall
> http://www.webpeak.com
> 1(727)527-3646
>
>
>
> Alan Knowles wrote:
>
|
|
|
|
|