If Conditionals

Learn the fundamentals on how to write if statements in Parsley.

Parsley provides {{if}} conditional statements for logic flow.

Checking Equality

When writing if conditionals you can check equality with a single equals character; =. Equality can also be inverted with a bang; !=.

If you're evaluating another Parsley expression including autogenerated fields inside of an if conditional use single curly brackets to wrap your expression. If you are expecting this variable to be a string (this includes ZUIDs) be sure to wrap it in quotes.

// Inner Parsley expression
{{ if {page.title} = Hello, World }}
It works!
{{end-if}}
// Inverted equality
{{if '{item.zuid}' != '{page.item_page}' }}
<a href="/" class="home"><img src="..." /></a>
{{end-if}}

If / Else

When writing an if conditional you can also specify an else condition.

{{ if {page.path_part} = special-page }}
This is the special page!
{{else}}
This is not the special page!
{{end-if}}