It’s important to remember that the purpose of template expressions is to help you write maintainable code. Keeping presentation-only expressions in the component template is a good way to do this, but not if your expressions are so complex you can’t read them. Use your best judgement for what works for you and your development team, both today, and six weeks after the last time you looked at your markup.
Additionally, while template expressions offer enhanced capabilities, certain limitations exist to maintain performance and security.
Complex template expressions is a pilot or beta service that is subject to the Beta Services Terms at Agreements - Salesforce.com or a written Unified Pilot Agreement if executed by Customer, and applicable terms in the Product Terms Directory. Use of this pilot or beta service is at the Customer’s sole discretion.
Note
Do not use complex template expressions in production. Use complex template expressions only for:
Development and testing
Proof of concept implementations
Internal tools and prototypes
Learning and experimentation
If you need similar functionality in production, use traditional approaches like getters, computed properties, or component methods until the feature is generally available.
Important
Version Requirement
Complex template expressions are supported for components with API version 66.0 and later. Components with API versions before 66.0 in their js-meta.xml file don’t support complex expressions. Expression evaluation falls back to basic property binding. Attempting to use a complex expression on a component with a lower API version will result in compiler errors.
this Keyword
The this keyword isn’t allowed in template expressions.
1<!-- ❌ Invalid -->2<div>{this.property}</div>3<!-- Error: 'this' is not allowed in template expressions -->45<!-- ✅ Valid - direct property access -->6<div>{property}</div>
1import{LightningElement}from "lwc";23export default class ThisKeywordComponent extends LightningElement{4 property = "value";5}
Function Declarations
Only arrow functions are supported, not function declarations.
1<!-- ❌ Invalid -->2<div>{function getName() { return 'John'; }()}</div>3<!-- Error: Function declarations are not allowed in template expressions -->45<!-- ✅ Valid -->6<div>{(() => 'John')()}</div>
Block Body Arrow Functions
Arrow functions with block bodies aren’t supported.
1<!-- ❌ Invalid -->2<div>{items.map(item => { return item.name; })}</div>3<!-- Error: Arrow functions with block bodies are not allowed -->45<!-- ✅ Valid -->6<div>{items.map(item => item.name)}</div>
Assignment operators aren’t allowed outside of arrow functions.
1<!-- ❌ Invalid -->2<div>{count = count + 1}</div>3<!-- Error: Assignment operators are not allowed outside arrow functions -->4<button>{count += 1}</button>5<!-- Error: Assignment operators are not allowed outside arrow functions -->
Update Operators Outside Arrow Functions
Update operators (++, --) aren’t allowed outside of arrow functions.
1<!-- ❌ Invalid -->2<div>{count++}</div>3<!-- Error: Update operators are not allowed outside arrow functions -->4<button onclick="{foo++}"></button>5<!-- Error: Update operators are not allowed outside arrow functions -->
New Operator
The new operator isn’t supported for creating instances.
1<!-- ❌ Invalid -->2<div>{new Date()}</div>3<!-- Error: 'new' operator is not allowed in template expressions -->4<button onclick="{() => new Day()}">Set Day</button>5<!-- Error: 'new' operator is not allowed in template expressions -->67<!-- ✅ Use component methods instead -->8<div>{currentDate}</div>
1import{LightningElement}from "lwc";23export default class NewOperatorComponent extends LightningElement{4 currentDate = new Date().toLocaleDateString();5}