Hello there,
I’ve to generate files based on personnal templates (actually no rules or syntax defined) and datas coming from my database.
Actually, I’ve a synthesis web page giving me all the information I want to use to fill my template. And I’m looking for a good solution for my template and the way to fill it.
I need to allow blocs with loops.
Here is an example of template (the idea, syntax is pseudo-code):
#tpl starts here
# Generated on {date}
{each:servers}
### {name} ###
server.name = {name}
server.ip = {ip}
{/each:servers}
Datas about servers are:
$servers = array(
array('name' => 'first', 'ip' => '192.168.1.3'),
array('name' => 'second', 'ip' => '192.168.1.7'),
array('name' => 'third', 'ip' => '192.168.1.4'),
);
Expected file:
#tpl starts here
# Generated on 20130309
### first ###
server.name = first
server.ip = 192.168.1.3
### second ###
server.name = second
server.ip = 192.168.1.7
### third ###
server.name = third
server.ip = 192.168.1.4
I can have different templates, depending on the config file I want to create.
So, is it possible to do with native yii functions or must I use an external parser ? If using an external parser (as extension), which could be the simplest ? I don’t need the power of a smarty, templates are quite simple (“each” loop, and probably “if” statement to un/comment some lines) ?
Important: I can’t use standard templates, the templates will be done by users who don’t know PHP and need a really simple language.
Thanks by advance.
Regards