Templating the Boolean field

The Boolean field will add a switch for a true or false values for the content authors to pick from.

Output boolean value

Here is an example of how to use the value from a Boolean field which has the API ID switch.

Here we are using a boolean value to decide whether a className is one value or the other.

  • ejs
  • pug
  • pug (API v1)
Copy
<% const position = document.data.switch%>
<div class="item <%= position ? 'right' : 'left' %>">Text positioned by Boolean value...!</div>
Copy
- const position = document.data.switch ? 'right' : 'left'
  div( class = position )
    h2 Text positioned by Boolean value...!
Copy
- const position = document.data.custom_type_name.switch.value ? 'right' : 'left'
  div( class = position )
    h2 Text positioned by Boolean value...!