XaminProject / handlebars.php

Handlebars processor for php
331 stars 134 forks source link

A way to use arbitrary text as arguments in custom helper #153

Closed jcubic closed 7 years ago

jcubic commented 7 years ago

I want to implement my own if helper that will have arbitrary expressions like this:

{{#if foo =~ /bar/}}
    foo is bar
{{/if}}

but this throw InvalidArgumentException: Malformed arguments string, the solution is to use quotes for the whole thing but it would be nice if the lib will allow to use any text.

JustBlackBird commented 7 years ago

There is only limited set of things that could be arguments. As far as I remember neither =~ nor /bar/ are not valid arguments. So the only option is to use strings like "=~" and "/bar/".

Also, I don't think that rewriting of one of built-in helpers is a good idea.

JustBlackBird commented 7 years ago

Also, you could implement a helper like:

{{#ifMatchRegExp value pattern}}
  Yep, it matches.
{{/ifMatchRegExp}}
jcubic commented 7 years ago

I've fixed this by adding quotes before calling render.