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

dot notation in manual #129

Open
quangv opened this issue Mar 22, 2012 · 6 comments
Open

dot notation in manual #129

quangv opened this issue Mar 22, 2012 · 6 comments

Comments

@quangv
Copy link

quangv commented Mar 22, 2012

I wanted to use mustache to iterate through arrays. I found the following, about dot notations.

{{.}}

It would seem that dot notations is part of mustache, but it's not found in the manual.

Two part question.

  1. Is mustache-5 the main manual?
  2. Should dot-notation be part of the manual?

Thanks, mustache is awesome btw :)

@pvande
Copy link
Contributor

pvande commented Mar 22, 2012

The man pages are definitely in need of some lovin'. We'll make sure that dot-notation gets into the next draft -- thanks!

@quangv
Copy link
Author

quangv commented May 14, 2012

Couple of cool other things that could add to manual (assuming these are supported and not just hacks)

Object Dot Notation works with Nested Objects

vars = {team : {mascot : 'cat'}}

{{team.mascot}}

Array Numeric Lookup

(though this is obvious, since most langs arrays are objects)

vars = {count:[[10, [1,2,3]]]}

{{0}}
{{#1}}
  {{.}}
{{/1}}

Dot Notation can be Iterated

vars = {
  test:[
    ['yes', 'no']
  ]
}

{{#test}}
  {{#.}}
    {{.}}
  {{/.}}
{{/test}}

Top-Level Arrays

vars = [{name:'cat'},{name:'dog'}]

{{#.}}
  {{name}}
{{/.}}

-reference

Any other cool features not yet documented in manual?

@kaldari
Copy link

kaldari commented Jun 11, 2015

Could someone on the mustache team at least comment about whether the features above are meant to be publicly used or if they are non-standard hacks that should not be relied upon?

@kaldari
Copy link

kaldari commented Jun 11, 2015

It looks like the dot notation, at least, is not in the mustache spec (https://github.com/mustache/spec).

@bobthecow
Copy link
Member

Depending on what you mean by "dot notation"...

if you mean the {{.}} thing above, that's an "implicit iterator", and it's covered in the spec here.

if you mean actual dot notation, e.g. {{foo.bar.baz}}, it's covered in the spec here and here.

olehermanse added a commit to olehermanse/libntech that referenced this issue Nov 13, 2020
The mustache manual doesn't mention `{{.}}` at all:

http://mustache.github.io/mustache.5.html

Mustache.js documentation does mention it:

https://github.com/janl/mustache.js/#non-empty-lists

But only what it should do when iterating over a list of strings.

Some references in the "spec":

mustache/mustache#129
https://github.com/mustache/spec/blob/master/specs/sections.yml#L141-L169

But no mention of what should happen in these edge cases / wrong usage.

So, I don't think we should copy the behavior of the mustache demo in this case, because

1. It's not described anywhere in the spec
2. It seems accidental:

Mustache template
```
{{.}}
```

Data:
```
[1,"a",{},[1,2]]
```

Output:
```
1,a,[object Object],1,2
```

JavaScript:

```
$ node
Welcome to Node.js v14.15.0.
Type ".help" for more information.
> String([1,2,3])
'1,2,3'
> String({})
'[object Object]'
> String(["a","b","c"])
'a,b,c'
> String([1,"a",{},[1,2]])
'1,a,[object Object],1,2'
```

See JIRA tickets for further explanation:
https://tracker.mender.io/browse/CFE-3457
https://tracker.mender.io/browse/CFE-3489

Ticket: CFE-3489 CFE-3457
Signed-off-by: Ole Herman Schumacher Elgesem <ole@northern.tech>
@jpo-tu
Copy link

jpo-tu commented Apr 26, 2023

We'll make sure that dot-notation gets into the next draft

Nothing about this in https://mustache.github.io/mustache.5.html

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

No branches or pull requests

6 participants