I'm new to Mustache templating so please be kind.
My approach is to create a new HTML file based on a template HTML. I successfully integrated Mustache on my CodeIgniter application, via:
require 'system/libraries/mustache/src/Mustache/Autoloader.php';
// Create instance of autoloader
Mustache_Autoloader::register();
// Instantiate Mustache class
$m = new Mustache_Engine;
echo $m->render('Hello, {{planet}}!', array('planet' => 'Mars'));
Now I have a template HTML located on application/templates/my_html_template.php
, this file contains HTML semantics having some variable template {{words}}. I do understand that I need to render this but I can't seem to understand how things work. Should I use file_get_contents
then fwrite
the rendered HTML from Mustache to create the desired output of a new HTML file to a certain directory?
The Mustache_Engine
constructor takes an array of options, one of them is the loader
. This class will be responsible to get the template content from the first parameter that passed to render
. The default loader is Mustache_Loader_StringLoader
but there's other loaders in the library you can use like Mustache_Loader_FilesystemLoader. This sould take care of the loading the template file part of the task. Once it rendered you can use file_put_contents()
to shove it into a file.