Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper names can be paths? #912

Closed
waynedpj opened this issue Nov 21, 2014 · 4 comments
Closed

helper names can be paths? #912

waynedpj opened this issue Nov 21, 2014 · 4 comments

Comments

@waynedpj
Copy link

consider this the helper version of #389: when trying to use "/" in helper names, e.g. {{string/upper "ahoy!"}} the helper registers OK but results in a Error: Missing helper: 'string/upper'. here is a simple JSFiddle to demonstrate. note that in the console i am outputting the registered helpers, and the helper with the slash in the name string/upper is registered and is a valid object key (same as with partials). also, wrapping the helper name in quotes 'string/upper' or escaping the slash ends up as invalid syntax.

use case is the same as with partials: organizing helpers for libraries/easier reuse/etc.

still investigating why this is not working, but please consider this a feature request if it is not a bug.

thanks.

@zordius
Copy link

zordius commented Nov 21, 2014

try to use [ ... ] to protect the name like this: {{[string/upper] foo.bar}}

Updated JSFiddle here: http://jsfiddle.net/0e7e2e4L/2/

@waynedpj
Copy link
Author

@zordius thanks, that does indeed work. does this work intentionally (i.e. language spec) or is this a side effect of turning the helper name into an object key? thanks again either way.

however, if you look at the updated JSFiddle you can see that a partial registered with a slash greet/ahoy does not need to be protected at all. in addition a partial name can be wrapped in [], '' or "", giving us the following working options for invoking a partial that has a / in its name:

    {{> greet/ahoy name="HB"}}
    {{> [greet/ahoy] name="HB"}}
    {{> "greet/ahoy" name="HB"}}
    {{> 'greet/ahoy' name="HB"}}

however helpers with slashes in their name can only be referenced by wrapping them in [].

IMHO it would be more natural and consistent if a helper name could be invoked in the same manner(s) as a partial name, as they are both just keys on an object.

@kpdecker
Copy link
Collaborator

The [] are intentional. See the segment-literal section here.

The first parameter in a normal mustache statement is tied to the paths functionality that are used to resolve nested structures and when this is a helper call the same applies.

Unfortunately partials are inconsistent with the reset of the language because they are not nested structures rather keys on the object, which is where the disconnect comes from. Unfortunately without a very compelling reason I don't think we can change any of this as that's a pretty big breaking change.

@waynedpj
Copy link
Author

waynedpj commented Dec 2, 2014

@kpdecker thanks for the follow up and explanation. my main reason for this change is consistency, which IMHO would make the language easier to learn/use, perhaps even maintain? though obviously you are the expert on that :) i guess this idea is in the same spirit as the request to make sub expressions use {{}} instead of (). again, i just see it as simplifying the language syntax a bit which i think could be very good, especially as features are added that introduce new syntax. however, at this point the effort needed might not be worth the pain and you are in a much better position to decide that. anyway, thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants