Building Solid Liquid Skills - First Look

Following the Power Platform Developer Saturday event many of the attendees asked me to publish the templates used in my presentation.

You can find the content of my initial template with explanation on how to use and the outputs below:

LIQUID AT FIRST GLANCE

Tags ( {% %} ), Content ( {{ }} ), Filters ( upcase )

  {% if user %}
    Hello, {{ user.fullname | upcase }}!
  {% else %}
    Hello world!
  {% endif %}

OUTPUT

Hello, ANTONIO DANTAS!

VARIABLE DECLARATION

A variable can be initialized using either assign or capture. Capture facilitates initialization when declaring multi-line content, or when using special character content.

{% assign foo = "bar " %}
{{ foo }}
  
{% capture my_variable %}
  I am being captured.
  Please save me!!! 
{% endcapture %}

{{ my_variable | newline_to_br}}

OUTPUT

bar

I am being captured.
Please save me!!!


Data Types

String

  {% assign string_a = 'Hello World' %}
  {% assign string_b = "Double quotes can also be used" %}
  {{string_a}}
  {{string_b}}

OUTPUT

Hello World

Double quotes can also be used


NUMBER

Note that ‘integer‘, and ‘decimal’ filters are only available in Liquid .NET.

{% assign pi = 3.14159 %}
  {{ pi | floor  }} <br/>
  {{ pi | integer  }} <br/>
  {{ pi | decimal }} <br/>
  {{ pi | round:3 }}

OUTPUT

3
3
3.14159
3.142


DATE TIME

Date formatting strings used by the ‘date:’ filter uses .NET notation instead of the Liquid format.

  {{ page.modifiedon | date: 'f' }} <br/>
  {{ now | date: 'MMMM dd, yyyy' }}

OUTPUT

Thursday, June 4, 2020 5:50 AM
June 08, 2020


ARRAY

 {% assign speakers = 'Danish, Yash, Raz, Victor' | split: ',' %}
  {% for speaker in speakers %}
    {{ speaker }} <br/>
  {% endfor %}

OUTPUT

Danish
Yash
Raz
Victor


DICTIONARY

  {% if request.params.size > 0 %}
    Request has {{ request.params.size }} params.
  {% endif %}

OUTPUT

Request has 93 params.


COMMENT TAG

  {% comment %} 
    
    This is a comment

  {% endcomment %}

Victor Dantas