Skip to content

Suggestion: More intuitive syntax for simple if comparisons #10

@dswitzer

Description

@dswitzer

The syntax for implementing simple comparisons is overly complex and I think there should be simpler method for adding simple comparisons to your template code.

For example, in jquery.tmpl, you could do:

<div class="base{{if varName == 'None'}} none{{/if}}">${varName}</div>

However, this simple comparison is much more difficult in the new engine. First, you've got to set:

$.views.allowCode = true;

And then your template ends up looking something like this:

<div class="base{{* if($view.data.varName == 'None'){ result += ' none';  } }}">{{=varName}}</div>

This is quite a bit more complicated to implement and much more difficult to interpret.

Any chance of being able to implement something like:

<div class="base{{#if equals(varName, 'None')}} none{{/if}}">{{=varName}}</div>

Where we have some functional helpers like equals(), not(), gt(), lt(), gte(), lte()--and with the potential to define more helper functions.

I can understand dropping to code view for more complex operations, but it seems like there should be a way to at least perform some simple comparisons w/out having to drop to the overly complex code syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions