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

Feature/conditional block #22

Closed
wants to merge 4 commits into from

Conversation

wesen
Copy link

@wesen wesen commented Jul 19, 2011

I'm writing a compiler, and for efficiency purposes (and also template "clarity", in that i can see when a conditional is meant rather than iteration/lambda/new context/conditional), I decided to add a {{?test}} construct that can be used for conditionals. Also allows a kind of shortcut syntax {{?test}}then{{^test}}else{{/test}}.

let me know what you think.

@zeelot
Copy link

zeelot commented Aug 25, 2011

+1, having to make a new method for checking whether something is empty before iterating over it is quite annoying. (I hope this is what I think it is O_o)

@wesen
Copy link
Author

wesen commented Aug 26, 2011

the way i implemented it is actually not for iteration. For iteration, usually, this should work, depending on the truthiness semantics of your implementation language

{{#product}}
Name: {{name}}
{{/product}}
{{^product}}
No products.
{{/product}}

Where is clear that you want to iterate over products. I use the above for things like:

{{?isLoggedIn}}Hello {{user}}.{{^isLoggedIn}}Login{{/isLoggedIn}}

@spullara
Copy link
Collaborator

I've implemented the ? tag but didn't do the else. Looks like a reasonable idea to me.

@Baggz
Copy link

Baggz commented Feb 3, 2012

+1

@ghost
Copy link

ghost commented Jan 28, 2017

It appears that d5c6d4e does not belong into this pull request.

ghost pushed a commit to devurandom/lustache that referenced this pull request Jan 28, 2017
Explicit conditional blocks are e.g. necessary to support introducing the
 expansion of a list with an optional header, like in the following example:

```mustache
{{?products}}
Product names:
  {{#products}}
  - {{name}}
  {{/products}}
{{/products}}
{{^products}}
No products
{{/products}}
```

See-Also: mustache/spec#22
See-Also: mustache/spec#55 (comment)
ghost pushed a commit to devurandom/lustache that referenced this pull request Jan 28, 2017
Explicit conditional blocks are e.g. necessary to support introducing the
 expansion of a list with an optional header, like in the following example:

```mustache
{{?products}}
Product names:
  {{#products}}
  - {{name}}
  {{/products}}
{{/products}}
{{^products}}
No products
{{/products}}
```

I did not include tests, because their data is included in the corresponding
 pull request to the Mustache spec.

See-Also: mustache/spec#22
See-Also: mustache/spec#55 (comment)
ghost pushed a commit to devurandom/lustache that referenced this pull request Feb 1, 2017
Explicit conditional blocks are e.g. necessary to support introducing the
 expansion of a list with an optional header, like in the following example:

```mustache
{{?products}}
Product names:
  {{#products}}
  - {{name}}
  {{/products}}
{{/products}}
{{^products}}
No products
{{/products}}
```

I did not include tests, because their data is included in the corresponding
 pull request to the Mustache spec.

See-Also: mustache/spec#22
See-Also: mustache/spec#55 (comment)
ghost pushed a commit to devurandom/lustache that referenced this pull request Feb 1, 2017
Explicit conditional blocks are e.g. necessary to support introducing the
 expansion of a list with an optional header, like in the following example:

```mustache
{{?products}}
Product names:
  {{#products}}
  - {{name}}
  {{/products}}
{{/products}}
{{^products}}
No products
{{/products}}
```

I did not include tests, because their data is included in the corresponding
 pull request to the Mustache spec.

See-Also: mustache/spec#22
See-Also: mustache/spec#55 (comment)
@wesen wesen closed this Aug 21, 2017
@ghost
Copy link

ghost commented Aug 22, 2017

What was the reason for closing this?

@wesen
Copy link
Author

wesen commented Aug 22, 2017 via email

@ghost
Copy link

ghost commented Aug 23, 2017

Shall I submit the patch in a new pull request?

@wesen
Copy link
Author

wesen commented Aug 23, 2017 via email

@ghost
Copy link

ghost commented Aug 23, 2017

That would probably be easier, yes. Are you still maintaining the specification and do you plan to make changes like these?

@wesen
Copy link
Author

wesen commented Aug 23, 2017 via email

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

5 participants