I found a question on stack overflow about loading a template file in php, which was fine, but I wish to loop a template file of one line, many times instead. The article I have read is here [PHP Content Separation. The best answer on that page was from prodigitalson with his function GetTemplate.
Now I wanted to use something like this, but if I put his function in a loop then it wouldn't be very efficient, as it would keep loading the same file many times.
So I tried this. I would get the html included. Then store it in a variable, before putting it in the loop. However it didn't work.
Here is my code. The data is already in an array called $result.
$salesTemp=$this->tempLine('salesTEM.php');
while($row = array_shift($result)):
echo $salesTemp;
endwhile;
private function tempLine($file){
ob_start();
require $file;
return ob_get_clean();
}
The problem is that my variable is not being updated in the template. Here is my template
<li class="list-group-item"><?php echo $Customer;?><span class="label label-primary pull-right">SALES</span></li>
So is there a way of re-writing this so my $Customer variable is updated.
I am doing this to try to keep php and html separate.
{% for item in array %} <p>{{item.customer}}</p> {% end %}Others are available, for example comper. If you really want to build one your own with a script syntax you can take a look at lexing