From 9ccbe2b61ced6e8a28c75f838d0b3fd2579706f6 Mon Sep 17 00:00:00 2001 From: success1308 Date: Mon, 20 Jan 2025 17:29:02 -0500 Subject: [PATCH] Update Liquid types documentation to include missing Object and Timestamp types with examples. Resolves #1884 --- _basics/types.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/_basics/types.md b/_basics/types.md index 8c209af53..3e945ce3d 100644 --- a/_basics/types.md +++ b/_basics/types.md @@ -11,6 +11,8 @@ Liquid objects can be one of six types: - [Nil](#nil) - [Array](#array) - [EmptyDrop](#emptydrop) +- [Object](#object) +- [Timestamp](#timestamp) You can initialize Liquid variables using [`assign`]({{ "/tags/variable/#assign" | prepend: site.baseurl }}) or [`capture`]({{ "/tags/variable/#capture" | prepend: site.baseurl }}) tags. @@ -155,3 +157,67 @@ You can check to see if an object exists or not before you access any of its att ``` Both empty strings and empty arrays will return `true` if checked for equivalence with `empty`. + +## Object + +Objects are key-value pairs that allow access to their attributes. They are commonly used to represent more complex data structures, such as user data. + +

Example

+ +liquid +{%- raw -%} +{% if user %} +Hello, {{ user.name }}! Your email is {{ user.email }}. +{% endif %} +{% endraw %} + +In this example, `user` is an object with attributes such as `name` and `email`. + +

Input

+ +```liquid +{%- raw -%} +{% assign user = site.users[0] %} +{% if user %} + Welcome, {{ user.name }}! +{% endif %} +{% endraw %} +``` + +

Output

+ +```text +Welcome, Tobi! +``` + +--- + +## Timestamp + +A `Timestamp` represents date and time values. You can format timestamps using the `date` filter. + +

Example

+ +liquid +{%- raw -%} +{{ article.published_at | date: "%A, %B %d, %Y" }} +{% endraw %} + +In this example, `article.published_at` is a timestamp that is formatted to display the day of the week, month, day, and year. + +

Input

+ +```liquid +{%- raw -%} +{% assign article = site.articles[0] %} +Published on: {{ article.published_at | date: "%B %d, %Y" }} +{% endraw %} +``` + +

Output

+ +```text +Published on: January 15, 2025 +``` + +Use the `date` filter to customize the format of your timestamp.