Search code examples
mustachemustache.php

Rendering Mustache Block with external templates


I'm using Mustache 2.7.0 and trying to play with Blocks pragma for the first time.

Basically, I call basic.mustache

{{< layout }}
{{$ title}}{{page.meta.name}}{{/ title}}
{{/ layout }}

calling the block layout.mustache

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <h1>{{$ title}}test{{/ title}}</h1>
    </body>
</html>

I see the value of page.meta.name appear on the page, but not the tags written in layout.mustache.
Anyone have an idea why?

PHP

$mustache = new Mustache_Engine(array(
    'pragmas' => [Mustache_Engine::PRAGMA_BLOCKS],
    'loader' => new Mustache_Loader_FilesystemLoader('htdocs/templates'),
    'partials_loader' => new Mustache_Loader_FilesystemLoader('htdocs/templates/partials/')
));

$tpl = $mustache->loadTemplate('basic');
echo $tpl->render( $this );

Solution

  • It seems that partials_loader are not compatibles with Pragma blocks.

    Removing this line:

    'partials_loader' => new Mustache_Loader_FilesystemLoader('htdocs/templates/partials/')
    

    Solved my problem.