nico65 Posted August 4, 2017 Share Posted August 4, 2017 Hi, I’m trying to implement mustache.php into processwire. https://github.com/bobthecow/mustache.php What I did so far and what worked with one problem is: put the “Mustache” Folder in site/template make a _init_mustache.php <?php // include Mustache require __DIR__ . '/Mustache/Autoloader.php'; Mustache_Autoloader::register(); //start the mustache engine $mustache = new Mustache_Engine(array( 'template_class_prefix' => '__MyTemplates_', 'cache' => dirname(__FILE__).'/tmp/cache/mustache', 'cache_file_mode' => 0666, // Please, configure your umask instead of doing this :) 'cache_lambda_templates' => true, 'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/Pattern'), 'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__).'/Pattern/Partials'), 'helpers' => array('i18n' => function($text) { // do something translatey here... }), 'escape' => function($value) { return htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); }, 'logger' => new Mustache_Logger_StreamLogger('php://stderr'), 'strict_callables' => false, )); call that _init_mustache.php in the _init.php include_once("./_init_mustache.php"); Now I have a site/template/portfolio.php where I call the template $tpl = $mustache->loadTemplate('02-objects-050-image-hovertext'); // loads __DIR__.'/views/foo.mustache'; $content .= $tpl->render(array( 'alltagstitle' => $alltagtitle, 'order' => '01', 'Title' => $title, 'SRC' => $resized_thumb->url, )); this works so far in mysite.com/portfolio but I also call it from here fields/gcp/portfolio.php $temp = wireRenderFile($config->paths->templates.'/portfolio.php'); $search = explode(",", $srch); $replace = explode(",", $rplc); $newtemp = str_replace($search, $replace, $temp); echo $newtemp; to include the portfolio part on other pages. (I use the module “fieldtype select file”) My problem is now, that on the page where I use that last method I get the error: Error: Call to a member function loadTemplate() on null (line 71 of /var/…./site/templates/portfolio.php) And the Notice: Notice: Undefined variable: mustache in /var/www/clients/client29/web166/web/eyeonu-v6/site/templates/portfolio.php on line 71 Fatal error: Call to a member function loadTemplate() on null in /var/www/clients/client29/web166/web/eyeonu-v6/site/templates/portfolio.php on line 71 line 71 is: $tpl = $mustache->loadTemplate('02-objects-050-image-hovertext'); // loads __DIR__.'/views/foo.mustache'; It looks that I somehow messed it up with the prependtemplatefiles, can anyone give me a tip? Link to comment Share on other sites More sharing options...
gmclelland Posted August 6, 2017 Share Posted August 6, 2017 Not sure how to help you, but you might be better off creating a TemplateEngineMustache module that extends the TemplateEngineFactory module: There is already sub modules created that you could look at for other template engines like Implementation of Twig: https://github.com/wanze/TemplateEngineTwig Implementation of Smarty: https://github.com/wanze/TemplateEngineSmarty Implementation of Jade (by dreerr, thanks!): https://github.com/dreerr/TemplateEngineJade https://github.com/dreerr/TemplateEnginePug I personally use TemplateEngineFactory with TemplateEngineTwig. Hope that helps 3 Link to comment Share on other sites More sharing options...
nico65 Posted August 7, 2017 Author Share Posted August 7, 2017 (edited) Thank you gmclelland, I'll take a look at the module, looks promising. ...ok, I have a modified version of the twig module for the "TemplateEngineFactory" Module. If someone is interested: https://github.com/cojaco/TemplateEngineMustache Edited August 7, 2017 by nico65 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now