PHP code example of phly / phly-mustache

1. Go to this page and download the library: Download phly/phly-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/ */

    

phly / phly-mustache example snippets


use Phly\Mustache\Mustache;


echo $mustache->render('some-template', $view);

use Phly\Mustache\Resolver\DefaultResolver;

$resolver = new DefaultResolver();
$resolver->addTemplatePath($path1);
$resolver->addTemplatePath($path2);

$resolver = $mustache->getResolver()->attach($defaultResolver);

use Phly\Mustache\Resolver\DefaultResolver;

$resolver = $mustache->getResolver()->fetchByType(DefaultResolver::class);

$resolver->addTemplatePath($path1, 'blog');
$resolver->addTemplatePath($path2, 'contact');

$resolver->setSuffix('html'); // use '.html' as the suffix

use Phly\Mustache\Pragma\ImplicitIterator as ImplicitIteratorPragma;

$mustache->getPragmas()->add(new ImplicitIteratorPragma());
$mustache->render('template-with-pragma', $view);

class View
{
    public $first_name = 'Matthew';

    public $last_name  = "Weier O'Phinney";

    public function full_name()
    {
        return $this->first_name . ' ' . $this->last_name;
    }
}

$view = new stdClass;
$view->first_name = 'Matthew';
$view->last_name  = "Weier O'Phinney";
$view->full_name  = function() use ($view) {
    return $view->first_name . ' ' . $view->last_name;
};
bash
$ php -S 0.0.0.0:8080 -t doc/html/