GitHub

{{#checkIf}} helper

An extended version of the #if block helper with support for operators. Useful if you need to compare two arguments in a non-standard way.

Supported operators:

  • '==',
  • '!=',
  • '===',
  • '!==',
  • '&&',
  • '||',
  • '<',
  • '<=',
  • '>',
  • '>='

Syntax:

{{#checkIf ARG_1 OPERATOR ARG_2}}
Code displayed when above condition is true
{{else}}
Code displayed when above condition is false
{{/checkIf}}

Example:

You can use:

{{#checkIf author '&&' author.avatar}}
    <img src="{{author.avatar}}" alt="" />
{{/checkIf}}

Instead of:

{{#if author}}
    {{#if author.avatar}}
        <img src="{{author.avatar}}" alt="" />
    {{/if}}
{{/if}}

We can also find out if we are in a particular post by ID; eg. add a code just for the post with ID=10

{{#post}}
   {{#checkIf id '==' 10}}
         your code here...
   {{/checkIf}}
{{/post}}
  

Subscribe

Get the latest Publii news, updates and more delivered directly to your email inbox

You can change your mind at any time by clicking the unsubscribe link in the footer of any email you receive from us, or by contacting us at contact@tidycustoms.net. By clicking below, you agree that we may process your information in accordance with our Privacy Policy.