If blocks

HTML doesn’t have a way of expressing logic, like conditionals and loops. Svelte does.

To conditionally render some markup, we wrap it in an if block:

  1. {#if user.loggedIn}
  2. <button on:click={toggle}>
  3. Log out
  4. </button>
  5. {/if}
  6. {#if !user.loggedIn}
  7. <button on:click={toggle}>
  8. Log in
  9. </button>
  10. {/if}

Try it — update the component, and click on the buttons.