eq
Render something if two values are equal.
{{#eq([EXPRESSION...])}}TRUTHY{{else}}FALSY{{/eq}}
Renders the TRUTHY
section if every EXPRESSION
argument is equal (===
).
<my-demo></my-demo>
<script type="module">
import {StacheElement} from "can";
class MyDemo extends StacheElement {
static view = `
{{# eq(this.state, 'loggedIn') }}
<button on:click="this.state ='loggedOut'">Log Out</button>
{{else}}
<button on:click="this.state = 'loggedIn'">Log In</button>
{{/ eq }}
`;
static props = {
state: ""
};
}
customElements.define("my-demo", MyDemo);
</script>
eq
can compare more than two values:
{{# eq(task.ownerId, task.assignedId, user.id) }} Delegate! {{/ eq }}
Parameters
- EXPRESSION
{Literal Expression|KeyLookup Expression|Call Expression}
:Two or more expressions whose return values will be tested for equality.
- TRUTHY
{sectionRenderer(context, helpers)}
:A subsection that will be rendered if each
EXPRESSION
argument eq equal. - FALSY
{sectionRenderer(context, helpers)}
:An optional subsection that will be rendered if one of the
EXPRESSION
arguments is not equal to one of the others.