Liquid in section

Interpolation

Interpolation is a way to print out the dynamic data inside the HTML structure.

Syntax

Description

@print(variable)

Print out the variable

@lang(variable)

Print out the variable or string which will be supported multiple

@attr()

Print out the escaped of variable into attribute of HTML element

liquid.json
{% assign shop_name = shop.name %}
<h1 class="@attr(section.settings.class)">
    Hello @print(section.settings.name)! Welcome to the {{ shop.shop_name }}
</h1>

Evaluate

The engine is built in Javascript, In some situations, it's useful to embed logic code into your views. You can use the blade @js directive to execute your logic code. It works similarly to <?php and ?> in PHP programming language.

Name

Syntax

Start

@js

End

@endjs

liquid.json
<ul>
@js
    let items = section.settings.items_group;
    items.map((item) => {
        print('<li>'+item.name+'</li>'); 
        // the print function works same with @print()
    })
@endjs
</ul>

Conditionals

You may construct if statements using the @if, @elseif, @else, and @endif directives. These directives function identically to their Javascript counterparts:

Name

Syntax

if

@if (conditions)

else if

@elseif (conditions)

else

@else

endif

@endif

unless

@unless(!conditions)

For convenience, Blade also provides an @unless directive:

Switch case

Switch statements can be constructed using the @switch, @case, @break, @default and @endswitch directives:

Name

Syntax

switch

@switch (variable)

case

@case (value)

break

@break or @endcase

default

@default

endswitch

@endswitch

For Loop

In addition to conditional statements, Engine provides simple directives for working with Javascript's loop structures. Again, each of these directives functions identically to their Javascript counterparts:

Name

Syntax

for

@for (contitional statements)

endfor

@endfor

elsefor

@elsefor // incase array has no items

endelse

@endelse

While loop

Name

Syntax

while

@while (conditions)

endwhile

@endwhile

If you love LayoutHub, could you consider posting an review? That would be awesome and really help us to grow our business, here is the linkarrow-up-right.

Last updated