Liquid Basics Dev
NationBuilder uses the open source liquid template language to access objects and variables. Liquid allows our customers complete design freedom while maintaining the integrity of our servers. There are two basic types of markup in liquid: Output and Tags.
Table of Contents
- Logic Tags
- Comparison & Logic Operators
- Output Tags
- Object Reference Guide
- Filters
- More Liquid & Template Examples
Tags are surrounded by {% a curly bracket and a percent %} and drive the logic of templates. They are responsible for loops and branching logic.
Logic Tags
Liquid logic tags use comparison and logic operators to test for true or false. Comparison operators are used to determine equality or difference between variables or values, while logical operators are used to determine the logic between them .
Comparison & Logic Operators
Equal
This conditional statement checks to see if the page slug equals blog. If it is true, it will display the include "banner."
Not Equal
This conditional statement checks to see if the page slug is not blog. If it is not, it will display the include "blog-ad."
Bigger Than
This conditional statement checks to see if the page headline is bigger than 0 characters. If it is true, it will display it.
Less Than
This conditional statement checks to see if the page has less than 1 donation. For everything else, it will display the words "JUST STARTED." If it has more, it will display the amount raised.
Bigger or Equal
This conditional statement checks to see if the page has petition signatures with images. If it is true, it will display petition images in a forloop.
Less or Equal
These conditional statements check to see if there are 1 or less than 1 RSVPs to an event. If true, it will display "rsvp" and if there are more than 1, it will display "rsvps".
Or
This conditional statement checks to see if the page slug is any of those, if any are true it will display the "signup_header" on those pages.
And
This conditional statement checks to see if the page has signatures with images, and if there are 4 or more. If both are true, it will display petition images in a forloop.
Contains
This conditional statement checks if a logged-in user is tagged as "Regional Organizer." If that is true, it will display the special admin nav.
Outputs are surrounded by {{ two curly brackets }} and are replaced with the data they reference. You can use these output variables to display dynamic content.
Output Variables and objective reference guide
User & Account Output Variables
|
All of these links go to separate pages.
Page Output Variables
All of these links go to separate pages.
Special Outputs
Produces a direct link to the javascript file: jquery.fancybox.pack.js, located under Pages>Theme>Files.
Now
Use the date filters below to customize the output of the {{ "now" }} drop
Filters
Filters are simple methods used in Output markup, and run from left to right. When there are no more filters, the template will receive the resulting string.
String Filters
Append
Appends an image at the end of the Page Headline output.
Appends the words 'by Author' to the end of the Page Headline output.
Capitalize
Capitalizes the first words in a page's headline field.
Date
- %a - The abbreviated weekday name ("Sun'')
- %A - The full weekday name ("Sunday'')
- %b - The abbreviated month name ("Jan'')
- %B - The full month name ("January'')
- %c - The preferred local date and time representation
- %d - Day of the month (01..31)
- %H - Hour of the day, 24-hour clock (00..23)
- %I - Hour of the day, 12-hour clock (01..12)
- %j - Day of the year (001..366)
- %m - Month of the year (01..12)
- %M - Minute of the hour (00..59)
- %p - Meridian indicator ("AM'' or "PM'')
- %S - Second of the minute (00..60)
- %U - Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
- %W - Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
- %w - Day of the week (Sunday is 0, 0..6)
- %x - Preferred representation for the date alone, no time
- %X - Preferred representation for the time alone, no date
- %y - Year without a century (00..99)
- %Y - Year with century
- %Z - Time zone name
- %% - Literal "%'' character
Will display the date in this format: "Sunday, September 29, 2012 at 6:30pm through October 01, 2012"
Default
The default value is returned if the variable resolves to nil or an empty string "". A string containing whitespace characters will not resolve to the default value.
Downcase
Converts the page headline output into all lowercase letters.
Escape
HTML tags are not rendered: <p>test</p>
Prepend
Adds an image in front of the Page Headline output.
Remove
Removes all occurrences of 'the' in the output for the blog post content tag.
Remove First
Removes only the first occurrence of 'the' in the output for the blog post content tag.
Replace
The resulting text would be "brown bears and brown ice caps"
Replace_first
The resulting text would be: "brown bears and polar ice caps"
Slice
The slice filter returns a substring, starting at the specified index. An optional second parameter can be passed to specify the length of the substring. If no second parameter is given, a substring of one character will be returned.
Split
The split filter takes on a substring as a delimiter to divide a string into an array.
Strip
Strips tabs, spaces, and newlines (whitespace) from both the left and right sides of a string.
Left Strip
Strips tabs, spaces, and newlines (whitespace) from only the left side of a string.
Right Strip
Strips tabs, spaces, and newlines (whitespace) from only the right side of a string.
Strip HTML
Removes all html tags from the blog post content.
Truncate Characters
Limits the amount of characters displayed from the Post Headline to 10.
Truncate Words
Limits the amount of characters displayed from the Post Headline to 10.
Paginate
Paginates the most recent blog posts.
Uniq
Removes any duplicate instances of an element in an array.
Upcase
Converts the page headline output into all capital letters.
URL Encode
Replaces any special characters with appropriate %XX replacements, including the ampersand (&): %3Chello%3E+%26+%3Cgoodbye%3E
Math Filters
Plus
Minus
Times
Divided By
Modulo
Divides an output by a number and returns the remainder.
Round
Rounds the output to the nearest integer.
Rounds the output to the nearest specified number of decimal places.
Ceil
Rounds an output up to the nearest integer.
Floor
Rounds an output down to the nearest integer.
Array Filters
Join
Combines the elements of an array with the character passed as the delimiter. The result is a single string.
First
Returns the first element of an array
Last
Returns the last element of an array
Map
Accepts an array element's attribute as a parameter and creates a string out of each array element's value.
Size
Returns the size of a string or an array.
Size can be used in dot notation, in cases where it needs to be used inside a tag: