ok, im a newb to php (about two weeks) after coming from an asp background. anyway, im trying to build a template class. i know, "theres heaps of template classes around", thing is, there either too simple (dont enable looping) or too complicated. i cant use a class if i dont know how it works.
i know the beuty of objects. yuo dont need to know how they work to use them, but honestly, i need to know how something works. drives me mad.
anyway, so ive decided i'd like to build my own.
so far i have this;
<?php
class skin
{
private $_template;
private $_output;
private $_array;
private $_fp;
public function skin($file)
{
$this->_template = $file;
$this->_output = "";
$this->_fp = fopen($this->_template,'r') or exit();
}
public function load($args)
{
while (!feof($this->_fp)) {
foreach ($args as $key => $value) {
$this->_output .= str_replace("{".$key."}",$value,fgets($this->_fp));
}
}
fclose($this->_fp);
}
public function render()
{
print $this->_output;
}
}
?>
this works fine, and will parse a simple template file such as;
<html>
<head>
<title>{title}</title>
</head>
<body>
<p>{content}</p>
</body>
</html>
but i would really like to build some sort of looping functionality. i could then use a template something like;
<html>
<head>
<title>{title}</title>
</head>
<body>
<table>
<tr>
{block=loop&id=user_details}
<td>{name}</td>
<td>{mail}</td>
{block=endloop&id=user_details}
</td>
</body>
</html>
ok, im not asking for code... just a push in the write direction.
ive tried to make one 'main' array storing each line of the file. then replacing the loop with a marker, and trying to store the loop in another array . but i still cant figure the logic.
sorry, i dont really have too much code, im kinda just looking for a brief description of how some of you would recomend doing this.
ps; i came up with the idea of defining a loop within a template using a string like this;
block=loop&id=user_details
thinking it would be an easy thing to parse using parse_str. any better ideas?