I'm developing a PHP templating engine1 and I want to allow PHP syntax alongside the templating syntax. My process currently is to compile the template into a php file (convert all template syntax to PHP), store it to disk and then load it using include
2. The compilation will only take place if the original template has been modified or if no compilation has ever been made.
However, there are a few issues with this approach:
Is there another approach to this?
For example, the following code:
<ul>
<?php forach( $list as $item ): ?>
<li>{{item}}</li>
<?php endforeach; ?>
</ul>
Would be compiled to:
<ul>
<?php forach( $list as $item ): ?>
<li><?php echo $item ?></li>
<?php endforeach; ?>
</ul>
eval
for this as it is both costly and dangerous.