XaminProject / handlebars.php

Handlebars processor for php
331 stars 132 forks source link

Get current helper content as string or tree #151

Closed jcubic closed 8 years ago

jcubic commented 8 years ago

I want to impement escape helper, for this to work I need to have access to text that's inside helper.

I can call $template->getTree(); method to get the whole tree of the template but not the current helper content tree.

Is there a way to get the string that's inside block helper?

everplays commented 8 years ago

Have a look here: https://github.com/XaminProject/handlebars.php/blob/198faa48d620807541dacf84fe03a785692f1203/tests/Xamin/HandlebarsTest.php#L427

You get a Template instance which has getSource method.

jcubic commented 8 years ago

getSource return whole template and I want to get the current helper content.

fzerorubigd commented 8 years ago

I think the source parameter is passed to helpers (third one if i can remmember correctly)

jcubic commented 8 years ago

Yes this work, thanks:

$engine->addHelper('escape', function ($template, $context, $arg, $source) {
    return $source;
});