zordius / lightncandy

An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ),
https://zordius.github.io/HandlebarsCookbook/
MIT License
608 stars 76 forks source link

Class instance method as helper function #342

Open jeff-pruvio opened 4 years ago

jeff-pruvio commented 4 years ago

The PHP Code:

protected function makeSomeText() { $php = LightnCandy\LightnCandy::compile($html, array( 'helpers' => array( "flags": LightnCandy\LightnCandy::FLAG_HANDLEBARS, "story"=>function($identifier, $options) { return $this->getTextForResponse($identifier); } ) ) ); }

The Issue:

This doesn't work for me (PHP doesn't like it - referencing $this in a non-object context), and I can't find anything in the documentation about calling a class instance method in a helper.