1

I am trying to define an alternative/default template loader path in case the first one is not found.

Currently I initialize mustache this way:

$m = new Mustache_Engine(array(
'loader' => new Mustache_Loader_FilesystemLoader($templates_path,array('extension'=>'.php'))
));

And then I render the template:

$m->render($my_template_path, $fields);

The render method is called several times under the same Mustache instance. This works fine, but I am not sure how to update the loader path without creating a new Mustache instance.

I have been reading the docs, but haven't got it to work. I've tried using $loader->load() instead of render. That allows me to change the path, but it doesn't render the variables.

gdaniel
  • 1,307
  • 2
  • 10
  • 17

1 Answers1

0

So... I had completely missed the CascadingLoader option which allows me to set multiple loaders. I got the fallback path to load by updating my code to:

$m = new Mustache_Engine(array(
    'loader'=> new Mustache_Loader_CascadingLoader(array(
               new Mustache_Loader_FilesystemLoader($templates_path,array('extension'=>'.php')),
               new Mustache_Loader_FilesystemLoader($alt_path,array('extension'=>'.php'))
    ))
));
gdaniel
  • 1,307
  • 2
  • 10
  • 17