-
Notifications
You must be signed in to change notification settings - Fork 132
Handlebars.js like helpers #74
Comments
You are right, it is too much work on developer to get a helper work the way they want it. However, I don't think neither me nor @fzerorubigd be able to work on this in near future. Yet, I can imagine that the result would look like this:
Any suggestions? |
I suggest to use helpers signature from handlebars.js. Namely: function helper($arg1, $arg2, ..., $argn, $options) {
return 'an output';
} @everplays, what do you think about backward compatibility? |
Yeah, that makes our API as close as possible to main implementation. We can either drop the BC or use reflection to find out if the last
|
We can keep the old style helpers too. For example another interface or On Tue, Aug 19, 2014 at 4:01 PM, Dmitriy S. Simushev <
|
I've thought more about the new helpers style. It seems that $helper = function ($positional_args, $options) {
// Helper's body
} style is the most comfortable for PHP. Here $options = array(
// Named arguments
'hash' => array(),
// A renderer for block helper
'fn' => function($context) {},
// A render for the else block
'inverse' => function($context) {},
// The current context.
// Just associative array with resolved variables without all that stuff from \Handlebars\Context
'context' => array(),
); All arguments are already parsed and resolved. Thus the helper should know nothing about the arguments parsing and resolving. I could try to implement it and send a pull request. But I cannot and don't want to keep backward compatibility. Thus, as I think, the next major version should be released with this changes. @fzerorubigd, @everplays, what do you think about it? |
Sorry for delay, @everplays is in imigration process (Goodluck dude :) ) And I have another pile of task in my issue tracker :) As I said before, backward compatibility is important, but we can break things when there is no another option. Thank you |
At the moment writing custom helpers is complicated for users who does not familiar with internal architecture of Handlebars.php. One should manually parse arguments, gets them from the context, render nested blocks, works with
else
section and so on.Is there any chance a simple, Handlebars.js like, interface will be implemented for helpers?
The text was updated successfully, but these errors were encountered: