HTML_Template_Flexy Usage
| From: | kevincarlson at houston dot rr dot com | Date: | Tue, 09 Aug 2005 20:54:34 +0000 |
| Subject: | HTML_Template_Flexy Usage | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-20342@lists.php.net to get a copy of this message | ||
Hi,
Does anyone have some documentation or working examples of the
HTML_Template_Flexy class (v1.2.1). I have managed to get a template
working as I expected when populating a form, but I get unexpected
results when trying with other tags. I have looked at the phpDocumentor
docs. on the PEAR site, and the manual, and googled the net, but there
seems to be a dire lack of documentation regarding usage of this sucker.
I have programmed PHP for a few years now, but am a newbie with regards
to Templating.
I have a photoalbum class, and it basically needs to export a number
of thumbnails, which ends up being a loop of <div><a><img></a></div>
tags. How can I fill in the <a><img> information? Here are some
excepts of what I have tried:
Template:
...
<div class="thumbnail" flexy:foreach="thumb_ids,key,value">
GET_THUMB HERE {k}
<img name="thumbimg[]" id="thumbimg[]" flexy:dynamic="yes">
</div>
...
PHP Code:
...
foreach ( $this->thumb_ids as $key=>$value ) {
$string_array[]="src=fosy_image.php?s=$this->session_name&id=".$img_info['id']."&thumb=true";
}
$this->elements['thumbimg[]'] = new HTML_Template_Flexy_Element('img');
$this->elements['thumbimg[]']->name='thumbimg[]';
$this->elements['thumbimg[]']->setAttributes($string_array);
$options = array(
'templateDir' => '/share/web/php/devel/fosy_photoalbum/templates',
'compileDir' =>
'/share/web/php/devel/fosy_photoalbum/compiled_templates',
'forceCompile' => 0,
'debug' => 0,
'locale' => 'en',
'compiler' => 'Standard',
'allowPHP' => true,
//http://marc.theaimsgroup.com/?l=pear-general&m=111215906527340&w=2
);
$output = new HTML_Template_Flexy($options);
$output->compile($template);
$output->outputObject( $this, $this->elements );
Output:
<div class="thumbnail">
GET_THUMB HERE
<img name="thumbimg[]" id="thumbimg[]"
src=fosy_image.php?s=fosy&id=6224&thumb=true
src=fosy_image.php?s=fosy&id=8650&thumb=true
src=fosy_image.php?s=fosy&id=8651&thumb=true
src=fosy_image.php?s=fosy&id=8652&thumb=true
src=fosy_image.php?s=fosy&id=8653&thumb=true
src=fosy_image.php?s=fosy&id=8655&thumb=true
src=fosy_image.php?s=fosy&id=8656&thumb=true
src=fosy_image.php?s=fosy&id=8707&thumb=true>
</div>
I have also tried various other templates & PHP vars, adding vars to
the controller class app. and to the Flexy_Element object, and I cannot
seem to get a handle on this. I know that these also fail in the template:
<img name="thumbimg{k}" id=thumbimg"{k}" flexy:dynamic="yes">
<img flexy:nameuses="key" name="thumbimg%s">
So am I totally off base with what I am trying? Is the
HTML_Template_Flexy system primarily for forms and not general usage
with all tags? I know this loop works fine in a template, and fills in
my form with the contents of my class prop. array $maxres:
<select name="maxres" id="maxres">
{foreach:maxres,key,val}
<option value="{val}">{val}</option>
{end:}
</select>
But the same type of code will not work with other tags contained in
loops. Sorry for the long post, but can someone point me in the right
direction?
Kevin