Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Template string interpolation

Aperta
#623 11 commenti 22 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
handlebars
Ambito
frontend

Direzione di ricerca

Inizia con il Handlebars parser e, se necessario, esamina come il pwn parser gestisce i nodi AST dei letterali stringa. Esamina come funziona già l’interpolazione nelle invocazioni tra parentesi angolari e confronta le sintassi proposte per le stringhe normali e i backtick. L’attività è completata quando saranno definiti una sintassi concordata, un piano di compatibilità o deprecazione e il supporto del parser, invece di una discussione di progettazione aperta.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

T-templates

Just some quick notes for the idea to open up the discussion.

It's not very common, but occasionally you need to do string interpolations in Handlebars. Today, the solution is to use the concat helper.

{{notification message=(concat @user.firstName " " @user.lastName " has added you as a friend!")}}

It's not so bad, but it does add some noise. It would be nicer, in my opinion, to have a string interpolation syntax.

Ideally, it would be nice if we could just use the normal string syntax:

{{notification message="{{@user.firstName}} {{@user.lastName}} has added you as a friend!"}}

Note that this already works in angle bracket invocations, so it aligns nicely:

<Notification @message="{{@user.firstName}} {{@user.lastName}} has added you as a friend!" />

This would work if we are designing the language from scratch. You can always escape the mustaches if you meant for them to be literal mustaches, same as any other positions. Unfortunately, this will be a breaking change. While rare, it is possible that there are existing string literals that uses mustaches for this purpose.

The good thing about this is they are by definition static. So one option is to detect existing usages of unescaped mustaches in string literals, deprecate them to clear the space, then add the interpolation feature in the next major version. In the meantime, we can create an addon for apps to opt-in.

Another option is to do what JavaScript (which had the same problem and didn't have the luxury of bumping major versions) and use a different syntax for interpolated strings, say backticks:

{{notification message=`{{@user.firstName}} {{@user.lastName}} has added you as a friend!`}}

Personally, I would prefer to do the former, as it feels more consistent overall.

In terms of implementation, ideally this would be supported in the handlebars parser directly, but if not, we can re-parse string literal AST node in our pwn parser. Because it already "works" today (kind of by definition, because you can put anything in a string literal), I don't think it will cause any technical parsing challenge/ambiguities. But this is all just a quick sketch so I could be missing something.

Lingua principale
Nessun dato sulla lingua
Stelle
801
Fork
411
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di emberjs/rfcs

Tutte le issue di emberjs/rfcs

Issue simili

Altre issue su Web Dev

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.