DEV Community

Cover image for Dativejs {{#if}} block
Tobi
Tobi

Posted on

Dativejs {{#if}} block

When building a project with dativejs you might want to conditionally render a tag / anything

Then 🤯 You might be like

🤔 How can I achieve that

Don't worry dativejs has it

That's why we introduced the {{#if}} block

Usage

{{#if isOpen}}
  <h1>It's open</h1>
{{/if}}
Enter fullscreen mode Exit fullscreen mode

What if you also need to show some stuffs if the condition value is false

There is also an {{:else}} and {{:else if}}

They work just same as the JavaScript if,else,else if

Usage

{{#if isOpened}}
  <h1>😇</h1>
{{:else}}
  <h1>😔</h1>
{{/if}}
Enter fullscreen mode Exit fullscreen mode

You can add the {{:else if}} also

{{#if isOpened}}
  <h1>😇</h1>
{{:else if isHated}}
  <h1>😐</h1>
{{:else}}
  <h1>😔</h1>
{{/if}}
Enter fullscreen mode Exit fullscreen mode

Thanks for reading

Next tutorial will be on the {{#each}} block

Top comments (0)