PHP code example of nod.st / cakephp-mustache

1. Go to this page and download the library: Download nod.st/cakephp-mustache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nod.st / cakephp-mustache example snippets



//./Config/bootstrap.php
CakePlugin::load(array(
    'CakeMustache'  => array(
        'bootstrap' => true
    )
));


//./Controller/AppController.ctp
class AppController extends Controller {
    public $helpers = array(
        'CakeMustache.Mustache' => array(
            'path'          => './../webroot/mustache',
            'extension'     => 'mustache',
            'viewVariables' => true
        )
    );
}


//For example, ./Config/bootstrap.php
Configure::write('Mustache.path', '/my/custom/and/awesome/folder/path/to/mustache/templates');


//./View/Layouts/default.ctp
echo $this->Mustache->render('test.mustache', array(
    'text'  => 'Hello Mustache!'
));
html
<!-- ./webroot/mustache/test.mustache -->
<p>Test1: {{text}}</p>
{{> test2}}