Created
March 26, 2014 22:03
-
-
Save jeffturcotte/9794620 to your computer and use it in GitHub Desktop.
Handlebars context helper concept
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'vendor/autoload.php'; | |
use Handlebars\Handlebars; | |
use Handlebars\Helpers; | |
use Handlebars\Loader\FilesystemLoader; | |
$helpers = new Helpers(); | |
$helpers->add('data', function($template, $context, $args, $source) { | |
$context->push(['injected' => 'this var was injected']); | |
$buffer = $template->render($context); | |
$context->pop(); | |
return $buffer; | |
}); | |
$engine = new Handlebars(array( | |
'loader' => new FilesystemLoader(__DIR__), | |
'helpers' => $helpers | |
)); | |
echo $engine->render('template', ['parent' => 'this is a parent var!']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
this var was injected | |
this is a parent var! | |
</div> | |
this is a parent var! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment