Conditionally render a block if the condition is false. Opposite of is
.
Parameters: value string|int
- the value to test against.
Data:
number = 5
Template:
{{#isnt number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/isnt}}
Renders to:
Never mind :(
Conditionally render a block if both values are truthy.
Parameters: values string|int
- the values to test against.
Data:
great = true
magnificent = true
Template:
{{#and great magnificent}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/and}}
Renders to:
Kiss my shiny metal ass!
Searches a string for the given value, and conditionally renders one block of content or another based on the result.
Parameters: String
(the value to test against) Default: undefined
Data:
---
truth: Assemble is the best static site generator for node.js!
---
Template:
{{#contains truth "best"}}
Absolutely true.
{{else}}
This is a lie.
{{/contains}}
Renders to:
Absolutely true.
Conditionally render a block if the value is greater than a given number (If x > y).
Parameters: value string|int
- the value to test against.
Data:
number = 5
Template:
{{#gt number 8}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/gt}}
Renders to:
Never mind :(
Conditionally render a block if the value is greater or equal than a given number (If x >= y).
Parameters: value string|int
- the value to test against.
number = 5
Template:
{{#gte number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/gte}}
Renders to:
Kiss my shiny metal ass!
Conditionally render a block if the value is greater than a given number (If x > y).
Parameters: none
{{#if_gt x compare=y}} ... {{/if_gt}}
Author: Dan Harper http://github.com/danharper
Conditionally render a block if the value is greater or equal than a given number (If x >= y).
Parameters: none
{{#if_gteq x compare=y}} ... {{/if_gteq}}
Author: Dan Harper http://github.com/danharper
Conditionally render a block if the condition is true (if x = y).
Parameters: string|int
(the value to test against) Default: undefined
Data:
---
number = 5
---
Template:
{{#is number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/is}}
Renders to:
Kiss my shiny metal ass!
If you are using data from YAML front matter or any specified JSON
and/or YAML
source files will get passed through to the context in your templates.
Data and Templates:
---
page:
title: About Us
---
{{#is page.title "Home"}}
<h1> About Us </h1>
{{else}}
<h1> My Blog </h1>
{{/is}}
Renders to:
<h1> About Us </h1>
Alias for is
. Considering consolidating
Conditionally render a block if the condition is true (If x = y).
Parameters: none
{{#ifeq x compare=y}} ... {{/ifeq}}
Credit: OOCSS
Compare the "left value" to the "right value" using any of the allowed operators.
==
===
!=
!==
<
>
<=
>=
typeof
Left
: value to compare againstOperator
: The operator to use for the comparison. Must be between quotes ">"
, "="
, "<="
and so on.Right
: value toOptions
: Options object for Handlebars.{{#compare [leftvalue ] [operator ] [rightvalue ]}}
foo
{{else }}
bar
{{/compare }}
{{#compare unicorns "<" ponies }}
I knew it, unicorns are just low-quality ponies!
{{/compare }}
{{#compare value ">=" 10}}
The value is greater or equal than 10
{{else }}
The value is lower than 10
{{/compare }}
Conditionally render a block if the value is less than a given number. Opposite of gt
.
Parameters: value string|int
- the value to test against.
Data:
number = 5
Template:
{{#lt number 3}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/lt}}
Renders to:
Never mind :(
Conditionally render a block if the value is less or equal than a given number. Opposite of gte
.
Parameters: value string|int
- the value to test against.
Data:
number = 5
Template:
{{#lte number 5}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/lte}}
Renders to:
Kiss my shiny metal ass!
Conditionally render a block if one of the values is truthy.
Parameters: values string|int
- the values to test against.
Data:
great = no
magnificent = true
Template:
{{#or great magnificent}}
Kiss my shiny metal ass!
{{else}}
Never mind :(
{{/or}}
Renders to:
Kiss my shiny metal ass!
Alias for isnt
Conditionally render a block if the condition is false (Unless x = y). Opposite of is
.
Parameters: none
{{#unless_eq x compare=y}} ... {{/unless_eq}}
Author: Dan Harper http://github.com/danharper
Unless greater than (Unless x > y)
Parameters: none
{{#unless_gt x compare=y}} ... {{/unless_gt}}
Author: Dan Harper http://github.com/danharper
"Unless x >= y". Render block, unless given value is greater than or equal to.
Parameters: none
{{#unless_gteq x compare=y}} ... {{/unless_gteq}}
Author: Dan Harper http://github.com/danharper
Render block, unless value is less than a given number (Unless x < y).
Parameters: none
{{#unless_lt x compare=y}} ... {{/unless_lt}}
Author: Dan Harper http://github.com/danharper
Render block, unless value is less than or equal to a given number (Unless x <= y).
Parameters: none
{{#unless_lteq x compare=y}} ... {{/unless_lteq}}
Author: Dan Harper http://github.com/danharper
See the template for this page →
Find an error? Let us know →