Liquid Template Engine

In Adxstudio (version 7.x), we can create templates using one of two methods.

  1. Page Templates – Custom .aspx pages deployed to the server
  2. Web Templates – Dynamics 365 Entity which is used to define dynamic content rendering

With the introduction of SaaS based Dynamics 365 Portals, the Page Template is no longer an option (For comparison of version 7.x and 8.x of Portals, click here).  Web Templates are built using a web templating system called “Liquid”.  Liquid can also be used inside Web Page’s Copy (HTML) field to render dynamic content.  We are heavily reliant on Web Templates and Liquid now than ever before.  This article serves as a quick reference guide which includes many resources to master Liquid.

What is Liquid?

Liquid is an open-source template language created by Shopify and written in Ruby.  The code base was ported to .NET by Tim Jones to another open-source project called DotLiquid.  Dynamics 365 Portals (also Adxstudio) use DotLiquid as the Liquid Template Engine of their portal.  DotLiquid is a complete port of the original Shopify Liquid project.  Therefore, the Shopify documentation is also valid and useful when designing Dynamics 365 Portal’s Liquid statements.

Where can I use Liquid?

  • Web Templates
  • Copy (HTML) field of a Web Page
  • Content Snippets

Liquid Basics

We need to learn three key terms, when using Liquid.

Tags – Liquid tags are the programming logic that tells templates what to do. Tags are wrapped in: {% %} characters.  Certain tags, such as for and cycle can take on parameters.

Objects – Liquid objects contain attributes to output dynamic content on the page. For example, the page object contains an attribute called title that can be used to output the title of a page.  Liquid objects are also often referred to as Liquid variables.  To output an object’s attribute, wrap the object’s name in {{ and }}.

Filters – Filters are simple methods that modify the output of numbers, strings, variables and objects. They are placed within an output tag {{ }} and are denoted by a pipe character |.

Tags

Control flow tags

if

unless

else / elsif

case / when

Multiple conditions (and / or)

and

or

Iteration tags

for (maximum of 50 results per page)

else

break

continue

limit

offset

range

reversed

cycle

tablerow

Variable tags

assign

capture

increment

decrement

Theme tags

Objects

Objects are specific to Dynamics 365 Portals.  Below are the commonly used objects.

Global Objects

entities – Allows you to load any Dynamics 365 entity by ID.

now – A date/time object that refers to the current UTC time, at the time the template is rendered.

page – Refers to the current portal request page.  The page object provides access to things like the breadcrumbs for the current page, the title or URL of the current page, and any other attributes or related entities of the underlying Dynamics 365 record.

params – A convenient shortcut for request.params.

request – Contains information about the current HTTP request.

settings – Allows you to load any Site Setting by name.

sitemap – Allows access to the portal site map.

sitemarkers – Allows you to load any Site Markers by name.

snippets – Allows you to load any Content Snippet by name.

user – Refers to the current portal user, allowing access to all attributes of the underlying Dynamics 365 contact record. If no user is signed in, this variable will be null.

weblinks – Allows you to load any Web Link Set by name or ID.

website – Refers to the portal Website record, allowing access to all attributes of the Dynamics 365 Website (adx_website) record for the portal.

Filters

Array filters

batch
concat
except
first
group_by
join
last
order_by
random
select
shuffle
size
skip
take
then_by
where

Entity List filters

current_sort
metafilters
reverse_sort

Date filters

Math filters

ceil
divided_by
floor
minus
modulo
plus
round
times

String filters

append
capitalize
downcase
escape
newline_to_br
prepend
remove
remove_first
replace
replace_first
split
strip_html
strip_newlines
text_to_html
truncate
truncate_words
upcase
url_escape
xml_escape

Type filters

boolean
decimal
integer
string

URL filters

add_query
base
host
path
path_and_query
port
remove_query
scheme

Additional filters

default
file_size
has_role
liquid

Thank you for visiting Dyn365Apps.com.

Follow me on Twitter to get the latest news, tips and tricks and more …

Until next time…

[Quick Reference] Liquid Template Engine Reference Manual for Dynamics 365 Portals
Tagged on:                     

Leave a Reply