You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to add a helper function($arg, $lambda) {…} that is able to load dynamically a subtemplate from the argument. So I'd like to accomplish {{> {{variable}} }} by doing {{#loadPartial}}{{variable}}{{/loadPartial}} but I'm sticking with this solution until now:
function mustacheLambdaHelperGetContext($lambda) {
$f = function(Mustache_LambdaHelper $lambda) {
return $lambda->context;
};
$f = Closure::bind($f, null, $lambda);
return $f($lambda);
}
/** … the same with ->mustache instead of ->context **/
$engine->addHelper('loadPartial', function($args, $lambda) {
$partialName = $lambda->render($args);
$context = mustacheLambdaHelperGetContext($lambda);
$engine = mustacheLambdaHelperGetMustache($lambda);
if ($partial = $engine->loadPartial($partialName)) {
return $partial->renderInternal($context);
}
});
And this solution is very ugly. So at least, if not implementing a LambdaHelper->renderPartial($name) or something, please implement a getContext() and a getMustache() method or make $context and $mustacheprotected instead of private.
The text was updated successfully, but these errors were encountered:
I'd like to add a helper
function($arg, $lambda) {…}
that is able to load dynamically a subtemplate from the argument. So I'd like to accomplish{{> {{variable}} }}
by doing{{#loadPartial}}{{variable}}{{/loadPartial}}
but I'm sticking with this solution until now:And this solution is very ugly. So at least, if not implementing a
LambdaHelper->renderPartial($name)
or something, please implement agetContext()
and agetMustache()
method or make$context
and$mustache
protected
instead ofprivate
.The text was updated successfully, but these errors were encountered: