0

I am trying to get a raw template that is already loaded by Mustache_Engine. On creation of the mustache object Filesystem_Loader instance is set up and pointing to the default directory.

$mustache = new Mustache_Engine( array(
    'loader' => new Mustache_Loader_FilesystemLoader( 'path-to-templates' )
) );

And later, for rendering the templates I use.

echo $mustache->render( 'template-name', $data ); 

The same template is used by mustache.js on server side, so i want to also print that template as inline script.

I could load the template from the filesystem manually with file_get_contents, but since that template is already loaded maybe there's a way to retrieve that from Mustache_Engine. Also, to use the file_get_contents i must use full path of the template and that just contradicts with the purpose of Mustache Template Loader.

Danijel
  • 12,408
  • 5
  • 38
  • 54

1 Answers1

3

After digging through the Mustache_Engine source, found the answer. getLoader() will get the current Mustache Template Loader instance, and load() function will load the template ( if is not already loaded ) and return it as string.

echo $mustache->getLoader()->load( 'template-name' );
Danijel
  • 12,408
  • 5
  • 38
  • 54