by Before Semicolon


Variable tag is one of the ways to create local context data.

When it comes to templating, variables help with reusing logic and piece of data to clean things a little and make templates easier to understand.

Instead of this:

	<li #repeat="$data.list.filter(n => n.price > 0)">{$}</li>
	Total price: {
			.filter(n => n.size > 10).reduce((acc, n) => n.price), 0)

Do this:

<variable name="pricedList" value="$data.list.filter(n => n.price > 0)"></variable>

	<li #repeat="pricedList">{$}</li>

<variable name="total" value="pricedList.reduce((acc, n) => n.price), 0)"></variable>

<p>Total price: {total}</p>

The value attribute

You can specify any value for your variable and you dont need curly braces.

Inner content

Anything you put inside the variable tag body will be treated as string. It cannot be HTML but templating binding can work.

<variable name="title">My string title</variable>
<!-- Same as above -->
<variable name="title" value="'My string title'"></variable>