liveBook · Manning

Template

As explained in Build a Frontend Web Framework (From Scratch)

An HTML-based representation of a component’s structure that a frontend framework transforms or interprets to create its view.

HTML templates describe a component’s view. Framework directives can change DOM elements’ behavior—for example, showing a paragraph only when application state indicates a discount. section 1.3.1

<p v-if="hasDiscount">
  You get a discount!
</p>

Vue uses v-if to conditionally display the paragraph. section 1.3.1

{#if hasDiscount}
<p>
  You get a discount!
</p>
{/if}

Svelte expresses the same condition with an if block. section 1.3.1

{hasDiscount && <p>You get a discount!</p>}

React expresses the condition in JSX rather than an HTML template directive. section 1.3.1

How Build a Frontend Web Framework (From Scratch) covers it

How deep it goes
Shows conditional-rendering syntax across frameworks and defers template compilation into JavaScript render functions to advanced material.
Examples
Compares a conditional discount paragraph in Vue, Svelte, and React.
What you can do after
Understand how Vue and Svelte templates and React JSX conditionally display an element.
How it connects
Connects templates with DOM elements, application state, conditional rendering, and JavaScript render functions.

Also explained in

Compare how 21 books explain template →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Frontend Web Framework (From Scratch). The section links point to the parts of the book it draws on.