liveBook · Manning

Template literal

A JavaScript string literal delimited by backticks that supports multiline text and embedded expressions.

How 3 Manning books explain it

Web Components in Action

An ECMAScript string literal delimited by backticks that supports interpolation and multiline content.

How it is used
Uses template literals to keep multiline HTML/CSS readable and insert values into Web Component markup.
How deep it goes
Works through backticks, placeholders, imported render functions, and generated menus; defers fuller expression syntax to an appendix.
Examples
Builds a business-card customizer with interpolated contact fields and generated logo and background selectors.
What you can do after
Build it from scratch: place a Web Component’s HTML/CSS in a separate JavaScript module and generate markup from supplied values.

Read how Web Components in Action explains template literal →

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

A JavaScript literal syntax that supports embedded expressions, multiline text, and optional tag functions for processing the literal parts and substitutions.

How it is used
Makes dynamic greetings and product HTML readable without chains of string concatenation.
How deep it goes
Explains interpolation, multiline literals, tagging, and evaluation-time reuse limits; poses tag implementation as an exercise.
Examples
Uses cart messages, multiline greetings, product HTML, and an object-to-HTML-attributes tag exercise.
What you can do after
Practice/perform writing interpolated multiline strings, wrapping literals for reuse, and designing a tag for object values.

Read how Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond explains template literal →

Building User-Friendly DSLs

A JavaScript literal syntax delimited by backticks that can represent multiline strings and interpolate expressions.

How it is used
Uses ES2015 template literals with embedded expressions to implement template functions that generate code from pieces of an AST.
How deep it goes
Explains multiline strings, backtick delimiters, embedded expressions, and template-function use, while deferring detailed reference information.
Examples
Demonstrates a generatedIndexJsx template function copying runtime/index.jsx and runs it through the generator command.
What you can do after
Build it from scratch: create a template function that emits generated code and invoke it from a generator.

Read how Building User-Friendly DSLs explains template literal →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.