javascriptphptemplatesmustachemustache.php

Mustache php space in templates


I have this template code:

{{#album}}
<h1>{{ hinfo.artist_name }}</h1>
<h2>{{ hinfo.name }}</h2>
{{/album}}

which renders:

<h1></h1><h2></h2>

Instead if I write:

{{#album}}
<h1>{{hinfo.artist_name}}</h1>
<h2>{{hinfo.name}}</h2>    
{{/album}}

it succesfully shows:

<h1>my artist</h1><h2>my album name</h2>

In the javascript version of the same library, this behaviour with blank spaces is not happening. I added a function helper in the php constructor:

$mustache = new Mustache_Engine( 
    array( 
        'loader' => new Mustache_Loader_FilesystemLoader( 
            self::$_dir, 
            array('extension' => '.mst') 
        ),
        /*
        'helpers' => array(
            'fn' => function($text, $render) {
                        $parsed = $render($text);
                        $date = date("F j, Y  h:i", (int) $parsed);
                        return $date;
                    }
        )*/
    )
);

but is not being executed in this example.

Could anyone tell me if this behavior is correct or is a bug in the mustache 2.10 version?


Solution

  • Everything appears to be working as expect. I'm not sure exactly what your issue is.

    In Mustache.php, {{hinfo.artist_name}} (no spaces) is correct syntax.

    In Mustache.js, {{ hinfo.artist_name }} (with spaces) is correct syntax.