The Ghost Themes Developer Hub

Welcome to the Ghost Themes developer hub. You'll find comprehensive guides and documentation to help you start working with Ghost Themes as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

unless

{{unless}} Helper - reverse conditional helper (else block)

Usage: {{#unless featured}}{{/unless}}

Type
Parameters
Attributes

conditional value (any type)

n/a

The {{#unless}} block helper comes built in with Handlebars.

Description

{{#unless}} is essentially the opposite of {{#if}}. If you want to test a negative conditional only, i.e. if you only need the {{else}} part of an {{#if}} statement, then {{#unless}} is what you need.

It works exactly the same as {{#if}} and supports both {{else}} and ^ negation if you want to get really confusing!

Unless also uses the exact same conditional evaluation rules as {{#if}}.

Example code

Basic unless example, will execute the template between its start and end tags only if featured evaluates to false.

{{#unless featured}}
  ...do something...
{{/unless}}

If you want, you can also include an else block, although in the majority of cases, if you need an else, then using {{#if}} is more readable:

// This is identical to if, but with the blocks reversed
{{#unless featured}}
  ...do thing 1...
{{else}}
  ...do thing 2...
{{/unless}}

All block helpers also support negation, but now you really should be using if!!

// The negation symbol means that this is identical to using if
{{^unless featured}}
  ...do thing 1...
{{else}}
  ...do thing 2...
{{/unless}}

unless

{{unless}} Helper - reverse conditional helper (else block)