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

Glimmer/Handlebars: Clarify glimmer handlebars template syntax (array access by index) #19519

Closed
fpauser opened this issue Apr 30, 2021 · 3 comments

Comments

@fpauser
Copy link
Contributor

fpauser commented Apr 30, 2021

In a project (ember-3.16) I just came across the following snippet:

{{#with item.properties.[0] as |firstProp|}}
  <span>
    {{firstProp.label}}
  </span>
{{/with}}

This works so far, but formatting this thing with the vsc plugin Prettier for handlebars got me

{{#with item.properties.0 as |firstProp|}}
  <span>
    {{firstProp.label}}
  </span>
{{/with}}

which no longer works and triggers a parse error.

To clarify things I looked though the ember docs, but array access by index is not mentioned.

Research in the prettier glimmer/ember-template-lint space resulted in the following statements:

  • .[index] syntax is invalid (but works)
  • .[index] syntax is bad practise
  • .index syntax is invalid and does not work

So the question remains: What is valid/invalid/bad/deprecated glimmer handlebars template syntax? What we are really missing here is a proper glimmer handlebars template syntax specification.

@fpauser fpauser changed the title Glimmer/Handlebars: Valid glimmer template syntax (array access by array index) Glimmer/Handlebars: Valid glimmer template syntax (array access by index) Apr 30, 2021
@fpauser fpauser changed the title Glimmer/Handlebars: Valid glimmer template syntax (array access by index) Glimmer/Handlebars: Clarify glimmer handlebars template syntax (array access by index) Apr 30, 2021
@jamescdavis
Copy link
Contributor

The recommended way to access an array by index in a template is to use the get helper, e.g.:

{{#with (get item.properties 0) as |firstProp|}}
  <span>
    {{firstProp.label}}
  </span>
{{/with}}

@jamescdavis
Copy link
Contributor

Also note that the with helper is deprecated in favor of the let helper.

{{#let (get item.properties 0) as |firstProp|}}
  <span>
    {{firstProp.label}}
  </span>
{{/let}}

@sandstrom
Copy link
Contributor

I'm doing some issue gardening 🌱🌿 🌷 and came upon this issue.

Fixed in ember-learn/guides-source#1750

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