06-02-2008, 01:00 AM
|
#3 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
The best way to do that would be to make a replaceTags version that accepts arrays and then iterates though them like:
PHP Code:
public function replaceTags($tags, $value = NULL)
{
if(is_array($tags) && sizeof($tags))
{
$value = array_values($tags);
$tags = array_map(Array($this, 'appendTags'), array_keys($tags));
}
$this->template = str_replace($value, $value, $this->template);
}
private function appendTags($variable)
{
return('<% ' . $variable . ' %>');
}
After seeing you use PHP5 I would use the __toString() magic method for the output like:
PHP Code:
public function __toString()
{
return((string) $this->template);
}
And then you can use it like:
PHP Code:
$template = new Template('test.html');
/* variables ... */
echo $template;
For the iterator to work then you are able to do like:
PHP Code:
while(/* statement */)
{
/* Assuming $data is an array */
$template = new Template('output.html');
$template->replaceTags($data);
echo $template;
}
I would also recommed you to use the private/protected/public modifiers =)
Hope this helps
__________________
|
|
|