Log Entry

Complex Template Expressions (Beta)

Feb 25, 2026 · 2 min read

I like this feature, but only in small doses.

LWC now lets you write JavaScript expressions directly in templates, for example:

<lightning-formatted-number
  value={amount * (1 + taxRate)}
  format-style="currency">
</lightning-formatted-number>

For tiny calculations, this is clean. No extra getter, less file hopping, and faster component authoring.

Where it works well

  • Basic math (x + y, percentages, small currency math)
  • Simple checks (items.length &gt; 10, null/empty guards)
  • Lightweight display-only decisions

Where it starts to hurt

  • Nested conditional logic
  • Long expressions with multiple operators
  • Anything you need to unit test in isolation
  • Anything business-critical

At that point, the template stops being declarative and starts feeling like inline logic soup.

My rule of thumb

If I need more than one quick read to understand the expression, it should be a getter.

Templates should explain structure. Getters (or controller logic) should explain behavior.

So yes, this beta is useful, but I would keep it limited to the truly simple cases.