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

New Helper: ifTest. Allow's for javascript expression evaluation. #566

Closed
wants to merge 1 commit into from

Conversation

tniswong
Copy link

http://jsfiddle.net/YsteK/

Consider the following context:
var context = { foo: "bar", baz: [ "qux", "quux" ] };

{{#ifTest 'foo == "bar"'}}
Foobar!
{{/ifTest}}

Result: Foobar!

{{#ifTest 'foo != "bar"'}}
Not Foobar!
{{else}}
Foobar!
{{/ifTest}}

Result: Foobar!

{{#each baz}}
{{#ifTest 'this == "qux"'}} baz contains a qux! {{/ifTest}}
{{/each}}

Result: baz contains a qux!

{{#with baz}}
{{#ifTest 'this.length > 0'}}
The length is greater than 0!
{{/ifTest}}
{{/with}}

Result: The length is greater than 0!

{{#each baz}}
{{#ifTest '@Index < baz.length - 1' baz=../baz}}
{{this}},
{{else}}
{{this}}.
{{/ifTest}}
{{/each}} Yay comma's!

Result: qux, quux. Yay comma's!

http://jsfiddle.net/YsteK/

Consider the following context:
var context = { foo: "bar", baz: [ "qux", "quux" ] };

{{#ifTest 'foo == "bar"'}}
    Foobar!
{{/ifTest}}

Result: Foobar!

--

{{#ifTest 'foo != "bar"'}}
    Not Foobar!
{{else}}
    Foobar!
{{/ifTest}}

Result: Foobar!

--

{{#each baz}}
    {{#ifTest 'this == "qux"'}} baz contains a qux! {{/ifTest}}
{{/each}}

Result: baz contains a qux!

--

{{#with baz}}
    {{#ifTest 'this.length > 0'}}
        The length is greater than 0!
    {{/ifTest}}
{{/with}}

Result: The length is greater than 0!

--

{{#each baz}}
    {{#ifTest '@Index < baz.length - 1' baz=../baz}}
        {{this}},
    {{else}}
        {{this}}.
    {{/ifTest}}
{{/each}} Yay comma's!

Result: qux, quux. Yay comma's!
@kpdecker
Copy link
Collaborator

kpdecker commented Jul 2, 2013

We are specifically logicless so I don't think we want to include this in the core library. If you publish this as a plugin project or a gist we can link to it in the README though.

@kpdecker kpdecker closed this Jul 2, 2013
@tniswong tniswong mentioned this pull request Jul 2, 2013
@tniswong
Copy link
Author

tniswong commented Jul 2, 2013

Here's the gist

https://gist.github.com/tniswong/5910264

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

Successfully merging this pull request may close these issues.

None yet

2 participants