jinnguyen / puja

A Django-like template engine for PHP. Puja also supports validate template syntax!
MIT License
5 stars 1 forks source link

Add check property and method exists #7

Closed max107 closed 11 months ago

max107 commented 10 years ago
<?php
ini_set('display_errors', 'On');
include '../puja.php';
$tpl = new Puja;
$tpl->template_dir = 'templates/';
$tpl->cache_dir = 'cache/';

class Test
{
    public function b()
    {
        return 321;
    }
}

$tpl->parse('test.tpl', [
    'a' => new Test
]);

Template:

{{ a.b }}

Compiled template:

<?php 
$pujaFilter = new TemplateFilter;
$pujaTags = new TemplateTags;
$ast_puja_template = '';
$ast_puja_template .= (isset($a['b']) ? $a['b'] : null);
$ast_puja_template .= '';
jinnguyen commented 10 years ago

In this version, Puja don't support to access a method, but it can access to property. We noted this idea for next version.

Thanks to @max107