How to Create & Edit Templates

Templates in Jobman are created using a templating language called Liquid. It allows you to insert variables, control structures and loops to control how your templates appear when they are rendered.

Objects

Objects contain the content that Liquid displays on a page. Objects and variables are displayed when enclosed in double curly braces: {{  and }} .

Input

{{ page.title }}

Output

Introduction

In this case, Liquid is rendering the content of the title  property of the page  object, which contains the text Introduction .

Tags

Tags create the logic and control flow for templates. The curly brace percentage delimiters {%  and %}  and the text that they surround do not produce any visible output when the template is rendered. This lets you assign variables and create conditions or loops without showing any of the Liquid logic on the page.

Input

{% ifuser %}

Hello {{ user.name }}!

{% endif %}

Output

Hello Adam!

Control flow

Control flow tags create conditions that decide whether blocks of Liquid code get executed.

if

Executes a block of code only if a certain condition is true .

Input

{% if product.title == "Awesome Shoes" %}

These shoes are awesome!

{% endif %}

Output

These shoes are awesome!

unless

The opposite of if  – executes a block of code only if a certain condition is not met.

Input

{% unless product.title == "Awesome Shoes" %}

These shoes are not awesome.

{% endunless %}

Output

These shoes are not awesome.

This would be the equivalent of doing the following:

{% if product.title != "Awesome Shoes" %}

These shoes are not awesome.

{% endif %}

elsif / else

Adds more conditions within an if  or unless  block.

Input

<!-- If customer.name = "anonymous" -->

{% if customer.name=="kevin" %}

Hey Kevin!

{% elsif customer.name=="anonymous" %}

Hey Anonymous!

{%else%}

Hi Stranger!

{%endif%}

Output

Hey Anonymous!

Iteration

Iteration tags repeatedly run blocks of code.

for

Repeatedly executes a block of code. For a full list of attributes available within a for loop, refer to the forloop object.

Input

{% for productin collection.products %}

{{ product.title }}

{% endfor %}

Output

hat shirt pants

else

Specifies a fallback case for a for loop which will run if the loop has zero length.

Input

{% for product in collection.products %}

{{ product.title }}

{% else %}

The collection is empty.

{% endfor %}

Output

The collection is empty.

For more information read the full documentation.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us