Template expressions support a wide range of computations within a component template. Use template expressions to reduce or eliminate the need for display-only properties or getters.
With simple property binding, dynamically computing a value for a property used in a template requires you to:
Define a getter that computes the value in the component class, and then
Reference that getter in the template.
1<template>2 {propertyName}3</template>
1import{LightningElement}from "lwc";2export default class Component extends LightningElement{3 get propertyName(){4 // Compute a value for propertyName5}6}
Template expressions are more powerful than basic property binding. They can contain any JavaScript expression that is valid in a template context. Additionally, complex expressions can be used for inline computations, which reduces the need for getters that solely compute or format values for a component’s user interface.
Compute and Format Values for Display Using Expressions
Template expressions are more powerful than basic property binding. They can contain any JavaScript expression that is legal in a template context. Complex expressions can be used for inline computations, which reduces the need for getters that solely compute or format values for a component’s user interface.
The following example illustrates a range of template expressions used to display user and status information. Additional examples covering specific syntax and use cases are offered throughout the documentation.