### Range parser examples
Source: https://hexdocs.pm/liquex/Liquex.Parser.Literal.html
Demonstrates valid inputs for the range parser.
```text
* "(1..5)"
* "(1..num)"
```
--------------------------------
### Whitespace parser examples
Source: https://hexdocs.pm/liquex/Liquex.Parser.Literal.html
Demonstrates valid inputs for the whitespace parser.
```text
* " "
* "
"
```
--------------------------------
### Literal parser examples
Source: https://hexdocs.pm/liquex/Liquex.Parser.Literal.html
Demonstrates valid inputs for the literal parser.
```text
* "true"
* "false"
* "nil"
* "3.14"
* "3"
* "'Hello World!'"
* ""Hello World!""
```
--------------------------------
### Initialize SimpleCache
Source: https://hexdocs.pm/liquex/Liquex.Cache.SimpleCache.html
Initializes the SimpleCache system. No specific setup or imports are required beyond the module itself.
```Elixir
@spec init() :: :ok
```
--------------------------------
### Examples of field parsing in Liquex
Source: https://hexdocs.pm/liquex/Liquex.Parser.Field.html
Demonstrates various valid formats for fields that can be parsed.
```text
* "my_variable"
* "my_variable.child_value"
* "my_variable[0]"
* "my_variable.child.value[3]"
```
--------------------------------
### RawTag Output Example
Source: https://hexdocs.pm/liquex/Liquex.Tag.RawTag.html
Shows the rendered output after the raw tag has been processed.
```text
In Handlebars, {{ this }} will be HTML-escaped, but {{{ that }}} will not.
```
--------------------------------
### EchoTag output example
Source: https://hexdocs.pm/liquex/Liquex.Tag.EchoTag.html
The resulting output from the echo tag loop.
```text
Hat Shirt Pants
```
--------------------------------
### Liquid Expression Example
Source: https://hexdocs.pm/liquex/Liquex.Tag.html
Example of a liquid expression tag.
```liquid
{% liquid echo "Hello World!" %}
```
--------------------------------
### Tablerow Tag Output Example
Source: https://hexdocs.pm/liquex/Liquex.Tag.TablerowTag.html
This is an example of the HTML output generated by the basic tablerow tag.
```html
|
Cool Shirt
|
Alien Poster
|
Batman Poster
|
Bullseye Shirt
|
Another Classic Vinyl
|
Awesome Jeans
|
```
--------------------------------
### RawTag Input Example
Source: https://hexdocs.pm/liquex/Liquex.Tag.RawTag.html
Demonstrates the input syntax for the raw tag to prevent processing of inner content.
```text
{% raw %}
In Handlebars, {{ this }} will be HTML-escaped, but {{{ that }}} will not.
{% endraw %}
```
--------------------------------
### Offset For Loop Iterations
Source: https://hexdocs.pm/liquex/Liquex.Tag.ForTag.html
Starts a for loop from a specified index, skipping earlier items.
```liquex
{% for item in array offset:2 %}
{{ item }}
{% endfor %}
```
--------------------------------
### Non-breaking whitespace parser examples
Source: https://hexdocs.pm/liquex/Liquex.Parser.Literal.html
Demonstrates valid inputs for the non-breaking whitespace parser.
```text
* " "
* " "
```
--------------------------------
### Add Liquex to Mix Dependencies
Source: https://hexdocs.pm/liquex/Liquex.html
Install Liquex by adding it to your project's dependencies in `mix.exs`.
```elixir
def deps do
[
{:liquex, "~> 0.13.1"}
]
end
```
--------------------------------
### Quoted string parser examples
Source: https://hexdocs.pm/liquex/Liquex.Parser.Literal.html
Demonstrates valid inputs for the quoted string parser, including escaped quotes.
```text
* "Hello World"
* 'Hello World'
* "Hello "World""
* 'Hello "World"'
* 'Hello 'World''
```
--------------------------------
### Defining and Using Custom Tags in Liquex
Source: https://hexdocs.pm/liquex/Liquex.html
Illustrates how to extend Liquex with custom tags by defining a module that implements `Liquex.Tag` and using a custom parser. This example creates a 'CustomTag' that prefixes output.
```elixir
defmodule CustomTag do
@moduledoc false
@behaviour Liquex.Tag
import NimbleParsec
@impl true
# Parse <>
def parse() do
text =
lookahead_not(string(">>"))
|> utf8_char([])
|> times(min: 1)
|> reduce({Kernel, :to_string, []})
|> tag(:text)
ignore(string("<<"))
|> optional(text)
|> ignore(string(">>"))
end
@impl true
def render(contents, context) do
{result, context} = Liquex.render!(contents, context)
{"Custom Tag: ", result}, context
end
end
defmodule CustomParser do
use Liquex.Parser, tags: [CustomTag]
end
iex> document = Liquex.parse!("<>", CustomParser)
iex> {result, _} = Liquex.render!(document, context)
iex> result |> to_string()
"Custom Tag: Hello World!"
```
--------------------------------
### Get and Update Variable
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Callback implementation for Access.get_and_update/3.
```elixir
@spec get_and_update(t(), any(), (any() -> any())) :: {any(), keyword() | map()}
```
--------------------------------
### CustomParser Integration
Source: https://hexdocs.pm/liquex/Liquex.Tag.html
Example of creating a custom parser that includes the newly defined custom tag.
```APIDOC
## CustomParser Integration
### Description
This module defines a custom parser for Liquex that includes `CustomTag` and `OtherTag`.
This allows Liquex to recognize and process these custom tags during parsing and rendering.
### Method
N/A (Module Definition)
### Endpoint
N/A
### Parameters
N/A
### Request Example
N/A
### Response
N/A
## Usage Example
### Description
Demonstrates how to use the `CustomParser` to parse and render Liquid content containing custom tags.
### Method
N/A (Code Execution)
### Endpoint
N/A
### Parameters
N/A
### Request Example
```elixir
defmodule CustomParser do
use Liquex.Parser, tags: [CustomTag, OtherTag]
end
# Assuming CustomTag and OtherTag are defined elsewhere
{:ok, document} = Liquex.parse("<>", CustomParser)
{result, _} = Liquex.render!(document, context)
```
```
--------------------------------
### CustomTag Implementation
Source: https://hexdocs.pm/liquex/Liquex.Tag.html
Example of implementing the Liquex.Tag behaviour to define a custom tag's parsing and rendering logic.
```APIDOC
## CustomTag Implementation
### Description
This module implements the `Liquex.Tag` behaviour to define a custom tag named `CustomTag`.
It includes functions for parsing the tag's content and rendering its output.
### Method
N/A (Module Implementation)
### Endpoint
N/A
### Parameters
N/A
### Request Example
N/A
### Response
N/A
## Callbacks
### parse()
#### Description
Returns a `NimbleParsec` expression to parse the custom tag.
#### Method
`@impl true`
#### Endpoint
N/A
#### Parameters
N/A
#### Request Body
N/A
#### Request Example
```elixir
def parse() do
text =
lookahead_not(string(">>\n"))
|> utf8_char([])
|> times(min: 1)
|> reduce({Kernel, :to_string, []})
|> tag(:text)
combinator
|> ignore(string("<<"))
|> optional(text)
|> ignore(string(">>"))
end
```
### render(contents, context)
#### Description
Renders the content of the custom tag.
#### Method
`@impl true`
#### Endpoint
N/A
#### Parameters
- **contents** (list()) - The parsed content of the tag.
- **context** (Liquex.Context.t()) - The current rendering context.
#### Request Body
N/A
#### Request Example
```elixir
def render(contents, context) do
{result, context} = Liquex.Render.render!(contents, context)
{["Custom Tag: ", result], context}
end
```
```
--------------------------------
### Defining and Using Custom Filters in Liquex
Source: https://hexdocs.pm/liquex/Liquex.html
Explains how to create and use custom filters by defining a module that implements `Liquex.Filter` and setting it in the context. This example adds a 'scream' filter.
```elixir
defmodule CustomFilter do
# Import all the standard liquid filters
use Liquex.Filter
def scream(value, _), do: String.upcase(value) <> "!"
end
context = Liquex.Context.new(%{}, filter_module: CustomFilter)
{:ok, template_ast} = Liquex.parse("{{'Hello World' | scream}}"
{result, _} = Liquex.render!(template_ast, context)
result |> to_string()
iex> "HELLO WORLD!"
```
--------------------------------
### Defining and Using Custom Liquex Filters
Source: https://hexdocs.pm/liquex/index.html
Provides an example of creating a custom filter module (`CustomFilter`) that extends Liquex's rendering capabilities. It demonstrates how to import standard filters and define a new one, then apply it within a template.
```elixir
defmodule CustomFilter do
# Import all the standard liquid filters
use Liquex.Filter
def scream(value, _), do: String.upcase(value) <> "!"
end
context = Liquex.Context.new(%{}, filter_module: CustomFilter)
{:ok, template_ast} = Liquex.parse("{{'Hello World' | scream}}")
{result, _} = Liquex.render!(template_ast, context)
result |> to_string()
iex> "HELLO WORLD!"
```
--------------------------------
### Examples of identifier parsing in Liquex
Source: https://hexdocs.pm/liquex/Liquex.Parser.Field.html
Demonstrates valid formats for identifiers, including those with numbers and a trailing question mark.
```text
* "my_variable"
* "is_valid?"
* "variable_1"
```
--------------------------------
### slice(value, start, length, _)
Source: https://hexdocs.pm/liquex/Liquex.Filter.html
Returns a substring of a specified length starting at a given index.
```APIDOC
## POST /liquex/filter/slice
### Description
Returns a substring of 1 character beginning at the index specified by the first argument. An optional second argument specifies the length of the substring to be returned.
### Method
POST
### Endpoint
/liquex/filter/slice
### Parameters
#### Request Body
- **value** (string) - Required - The input string.
- **start** (integer) - Required - The starting index for the slice. Negative indices count from the end of the string.
- **length** (integer) - Optional - The length of the substring to return. Defaults to 1 if not provided.
### Request Example
```json
{
"value": "Liquid",
"start": 2,
"length": 5
}
```
### Response
#### Success Response (200)
- **result** (string) - The extracted substring.
#### Response Example
```json
{
"result": "quid"
}
```
```
--------------------------------
### CaseTag Switch Statement Example
Source: https://hexdocs.pm/liquex/Liquex.Tag.CaseTag.html
Use `case` to initialize a switch statement and `when` to define conditions. An optional `else` block handles cases where no conditions are met. This is useful for executing specific code blocks based on variable values.
```liquid
{% assign handle = "cake" %}
{% case handle %}
{% when "cake" %}
This is a cake
{% when "cookie", "biscuit" %}
This is a cookie
{% else %}
This is not a cake nor a cookie
{% endcase %}
```
```text
This is a cake
```
--------------------------------
### Slice a string
Source: https://hexdocs.pm/liquex/Liquex.Filter.html
Returns a substring starting at a specific index with an optional length.
```elixir
iex> Liquex.Filter.slice("Liquid", 0, %{})
"L"
iex> Liquex.Filter.slice("Liquid", 2, %{})
"q"
iex> Liquex.Filter.slice("Liquid", 2, 5, %{})
"quid"
```
```elixir
iex> Liquex.Filter.slice("Liquid", -3, 2, %{})
"ui"
```
--------------------------------
### Render Liquid Object
Source: https://hexdocs.pm/liquex/Liquex.Tag.ObjectTag.html
Example of using double curly braces to render a page title property.
```liquid
{{ page.title }}
```
```text
Introduction
```
--------------------------------
### AssignTag Usage
Source: https://hexdocs.pm/liquex/Liquex.Tag.AssignTag.html
Examples of how to use the assign tag to create boolean and string variables in Liquid templates.
```APIDOC
## AssignTag Usage
### Description
Creates a new named variable within the Liquid template context.
### Examples
#### Boolean Assignment
Input:
{% assign my_variable = false %}
{% if my_variable != true %}
This statement is valid.
{% endif %}
Output:
This statement is valid.
#### String Assignment
Input:
{% assign foo = "bar" %}
{{ foo }}
Output:
bar
```
--------------------------------
### Tablerow Tag Output with 2 Columns
Source: https://hexdocs.pm/liquex/Liquex.Tag.TablerowTag.html
Example output of the tablerow tag when the 'cols' parameter is set to 2.
```html
|
Cool Shirt
|
Alien Poster
|
|
Batman Poster
|
Bullseye Shirt
|
|
Another Classic Vinyl
|
Awesome Jeans
|
```
--------------------------------
### Use Continue Tag in Liquex Loop
Source: https://hexdocs.pm/liquex/Liquex.Tag.ContinueTag.html
Use the continue tag within a Liquex loop to skip the current iteration when a condition is met. This example demonstrates skipping the iteration when 'i' equals 4.
```liquex
{% for i in (1..5) %}
{% if i == 4 %}
{% continue %}
{% else %}
{{ i }}
{% endif %}
{% endfor %}
```
--------------------------------
### init()
Source: https://hexdocs.pm/liquex/Liquex.Cache.SimpleCache.html
Initializes the SimpleCache system.
```APIDOC
## init()
### Description
Initializes the basic caching system that uses ETS.
### Method
N/A (Function call)
### Response
- **Return Value** (:ok) - Returns :ok upon successful initialization.
```
--------------------------------
### Create LocalFileSystem Instance
Source: https://hexdocs.pm/liquex/Liquex.LocalFileSystem.html
Creates a new Liquex.LocalFileSystem instance. The root path is where templates are stored, and the pattern defines how template filenames are constructed. The default pattern is "_%s.liquid".
```elixir
iex> file_system = Liquex.LocalFileSystem.new("/some/path")
```
```elixir
iex> file_system = Liquex.LocalFileSystem.new("/some/path", "%s.html")
```
--------------------------------
### Liquex.LocalFileSystem Functions
Source: https://hexdocs.pm/liquex/Liquex.LocalFileSystem.html
This section details the functions available in the Liquex.LocalFileSystem module, including how to create a new file system instance and how to generate full paths for template files.
```APIDOC
## Liquex.LocalFileSystem Functions
### Description
Provides functions to interact with the local file system for template retrieval.
### Functions
#### `new(root_path, pattern \"_%%s.liquid\") :: t()`
Creates a new `Liquex.LocalFileSystem` struct.
- **root_path** (String.t()) - The root directory for template files.
- **pattern** (String.t(), optional) - The pattern for template filenames. Defaults to `"_%%s.liquid"`. `%s` is replaced with the template name.
**Example:**
```elixir
file_system = Liquex.LocalFileSystem.new("/some/path")
```
#### `full_path(local_file_system, template_path) :: String.t()`
Generates the full path for a given template path within the file system.
- **local_file_system** (t()) - The `Liquex.LocalFileSystem` struct.
- **template_path** (String.t()) - The relative path or name of the template.
**Example:**
```elixir
file_system = Liquex.LocalFileSystem.new("/some/path")
Liquex.LocalFileSystem.full_path(file_system, "mypartial")
# Returns: "/some/path/_mypartial.liquid"
file_system_custom_pattern = Liquex.LocalFileSystem.new("/some/path", "%s.html")
Liquex.LocalFileSystem.full_path(file_system_custom_pattern, "mypartial")
# Returns: "/some/path/mypartial.html"
```
### Types
#### `t()`
Represents the `Liquex.LocalFileSystem` struct.
```elixir
%Liquex.LocalFileSystem{pattern: String.t(), root_path: String.t()}
```
```
--------------------------------
### Basic Liquex Parsing and Rendering
Source: https://hexdocs.pm/liquex/Liquex.html
Demonstrates the basic usage of Liquex for parsing a Liquid template string and rendering it with provided variables.
```elixir
iex> {:ok, template_ast} = Liquex.parse("Hello {{ name }}!")
iex> {content, _context} = Liquex.render!(template_ast, %{"name" => "World"})
iex> content |> to_string()
"Hello World!"
```
--------------------------------
### Initialize Context with Different Environments
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Demonstrates how to initialize a new Liquex context with variables assigned to different environment levels, affecting variable lookup precedence.
```elixir
iex> context = Liquex.Context.new(%{hello: "environment"})
iex> Access.get(context, "hello")
"environment"
iex> context = Liquex.Context.new(%{}, scope: %{hello: "scope"})
iex> Access.get(context, "hello")
"scope"
iex> context = Liquex.Context.new(%{}, static_environment: %{hello: "static environment"})
iex> Access.get(context, "hello")
"static environment"
```
--------------------------------
### Initializing Liquex Simple Cache
Source: https://hexdocs.pm/liquex/Liquex.html
Demonstrates how to initialize the built-in ETS-based cache for the render tag. Caching is disabled by default.
```elixir
:ok = Liquex.Cache.SimpleCache.init()
context = Context.new(%{...}, cache: Liquex.Cache.SimpleCache)
```
--------------------------------
### Get Variable from Context
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Function specification for retrieving a variable with an optional default value.
```elixir
@spec get(t(), any(), any()) :: any()
```
--------------------------------
### Get size of string or array
Source: https://hexdocs.pm/liquex/Liquex.Filter.html
Returns the character count of a string or the item count of an array.
```elixir
iex> Liquex.Filter.size("Ground control to Major Tom.", %{})
28
iex> Liquex.Filter.size(~w(apples oranges peaches plums), %{})
4
```
--------------------------------
### Defining and Using Custom Liquex Tags
Source: https://hexdocs.pm/liquex/index.html
Illustrates how to extend Liquex with custom tags by defining a `CustomTag` module that implements the `Liquex.Tag` behavior. This includes parsing logic for the custom tag and its rendering behavior, then integrating it with a custom parser.
```elixir
defmodule CustomTag do
@moduledoc false
@behaviour Liquex.Tag
import NimbleParsec
@impl true
# Parse <>
def parse() do
text =
lookahead_not(string(">>"))
|> utf8_char([])
|> times(min: 1)
|> reduce({Kernel, :to_string, []})
|> tag(:text)
ignore(string("<<"))
|> optional(text)
|> ignore(string(">>"))
end
@impl true
def render(contents, context) do
{result, context} = Liquex.render!(contents, context)
{["Custom Tag: ", result], context}
end
end
defmodule CustomParser do
use Liquex.Parser, tags: [CustomTag]
end
iex> document = Liquex.parse!("<>", CustomParser)
iex> {result, _} = Liquex.render!(document, context)
iex> result |> to_string()
"Custom Tag: Hello World!"
```
--------------------------------
### Continue Offset with Limit
Source: https://hexdocs.pm/liquex/Liquex.Tag.ForTag.html
Demonstrates using 'continue' with 'offset' to resume a loop from where a previous loop with the same iterator left off.
```liquex
{% for item in array limit: 3 %}
{{ item }}
{% endfor %}
{% for item in array limit: 3 offset: continue %}
{{ item }}
{% endfor %}
```
--------------------------------
### render!/2
Source: https://hexdocs.pm/liquex/Liquex.html
Renders a Liquex AST document with the provided context.
```APIDOC
## render!(document, context)
### Description
Render a Liquex AST document with the given context.
### Parameters
- **document** (document_t) - Required - The AST document to render.
- **context** (Liquex.Context.t | map) - Optional - The context data for rendering (defaults to %{}).
### Response
- **Success** ({iodata(), Liquex.Context.t()}) - Returns the rendered output and the final context.
```
--------------------------------
### decrement tag
Source: https://hexdocs.pm/liquex/Liquex.Tag.IncrementTag.html
Creates and outputs a new number variable starting at -1, decreasing by 1 on each subsequent call.
```APIDOC
## decrement
### Description
Creates and outputs a new number variable with initial value -1. On subsequent calls, it decreases its value by one and outputs the new value. Variables declared using decrement are independent from variables created using assign or capture.
### Request Example
{% decrement variable %}
{% decrement variable %}
{% decrement variable %}
### Response
-1 -2 -3
```
--------------------------------
### increment tag
Source: https://hexdocs.pm/liquex/Liquex.Tag.IncrementTag.html
Creates and outputs a new number variable starting at 0, increasing by 1 on each subsequent call.
```APIDOC
## increment
### Description
Creates and outputs a new number variable with initial value 0. On subsequent calls, it increases its value by one and outputs the new value. Variables created using increment are independent from variables created using assign or capture.
### Request Example
{% increment my_counter %}
{% increment my_counter %}
{% increment my_counter %}
### Response
0 1 2
```
--------------------------------
### UnlessTag Example in Liquex
Source: https://hexdocs.pm/liquex/Liquex.Tag.UnlessTag.html
Use the UnlessTag to conditionally render content when a product's title is not a specific value. This tag requires no special imports.
```liquex
{% unless product.title == "Awesome Shoes" %}
These shoes are not awesome.
{% endunless %}
```
--------------------------------
### Parse and Render Content
Source: https://hexdocs.pm/liquex/Liquex.Tag.html
Use the custom parser to process liquid content.
```elixir
{:ok, document} = Liquex.parse("<>", CustomParser)
{result, _} = Liquex.render!(document, context)
```
--------------------------------
### Implement a Custom Tag
Source: https://hexdocs.pm/liquex/Liquex.Tag.html
Create a module implementing the Liquex.Tag behaviour to define custom parsing and rendering logic.
```elixir
defmodule CustomTag do
@behaviour Liquex.Tag
import NimbleParsec
@impl true
# Parse <>
def parse() do
text =
lookahead_not(string(">> "))
|> utf8_char([])
|> times(min: 1)
|> reduce({Kernel, :to_string, []})
|> tag(:text)
combinator
|> ignore(string("<<"))
|> optional(text)
|> ignore(string(">>"))
end
@impl true
def render(contents, context) do
{result, context} = Liquex.Render.render!(contents, context)
{["Custom Tag: ", result], context}
end
end
```
--------------------------------
### Liquex CycleTag Basic Usage
Source: https://hexdocs.pm/liquex/Liquex.Tag.CycleTag.html
Demonstrates the basic usage of the cycle tag to loop through a list of strings.
```APIDOC
## POST /api/cycle
### Description
Loops through a group of strings and prints them in the order that they were passed as arguments. Each time cycle is called, the next string argument is printed. Cycle must be used within a for loop block.
### Method
POST
### Endpoint
/api/cycle
### Request Body
- **strings** (array) - Required - An array of strings to cycle through.
### Request Example
```json
{
"strings": ["one", "two", "three"]
}
```
### Response
#### Success Response (200)
- **output** (string) - The next string in the cycle.
#### Response Example
```json
{
"output": "one"
}
```
```
--------------------------------
### Using BreakTag in Liquex Loop
Source: https://hexdocs.pm/liquex/Liquex.Tag.BreakTag.html
This snippet demonstrates how to use the `break` tag within a Liquex loop to stop iteration when a condition is met. It requires no special setup beyond standard Liquex syntax.
```liquex
{% for i in (1..5) %}
{% if i == 4 %}
{% break %}
{% else %}
{{ i }}
{% endif %}
{% endfor %}
```
--------------------------------
### Liquex.Context.fetch/2
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Looks up a variable within the current scope, environment, or static environment.
```APIDOC
## fetch(context, key)
### Description
Look up variable within the current scope. If the scope does not define the variable, it is then looked up in the environment. Lastly, if that fails, it falls back to the static environment.
### Parameters
#### Request Body
- **context** (t) - Required - The context to search.
- **key** (any) - Required - The key to look up.
### Response
#### Success Response (200)
- **result** (:error | {:ok, any}) - Returns the value if found, otherwise :error.
```
--------------------------------
### Render Tag Usage
Source: https://hexdocs.pm/liquex/Liquex.Tag.RenderTag.html
Documentation for the {% render %} tag, including parameter passing, object assignment, and iteration.
```APIDOC
## {% render "template-name" %}
### Description
Inserts the rendered content of another template within the current template. Variables are scoped to the rendered template and are not shared with the parent.
### Parameters
- **template-name** (string) - Required - The name of the template to render (without .liquid extension).
- **parameters** (key: value) - Optional - Variables to pass to the rendered template.
- **with** (object) - Optional - Passes a single object to the template, optionally aliased with 'as'.
- **for** (enumerable) - Optional - Renders the template once for each item in an enumerable, optionally aliased with 'as'.
### Examples
#### Basic Render
{% render "template-name" %}
#### Passing Variables
{% assign my_variable = "apples" %}
{% render "name", my_variable: my_variable, my_other_variable: "oranges" %}
#### Using 'with'
{% render "product" with featured_product as product %}
#### Using 'for'
{% render "product_variant" for variants as variant %}
```
--------------------------------
### Nim callback for rendering Liquex tags
Source: https://hexdocs.pm/liquex/Liquex.Tag.RenderTag.html
Callback implementation for `Liquex.Tag.render/2`. This function is responsible for rendering Liquex tags within a given context.
```nim
Callback implementation for `Liquex.Tag.render/2`.
```
--------------------------------
### Liquex.Context.new/2
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Creates a new context to store the current state of a liquid template during the render phase.
```APIDOC
## new(environment, opts)
### Description
Create a new `Context` using a predefined variables map.
### Parameters
#### Request Body
- **environment** (map) - Required - Predefined variables map.
- **opts** (Keyword) - Optional - Configuration options including :static_environment, :scope, :filter_module, :file_system, and :cache_prefix.
### Response
#### Success Response (200)
- **t()** (struct) - Returns a new Liquex.Context struct.
```
--------------------------------
### Basic For Loop in Liquex
Source: https://hexdocs.pm/liquex/Liquex.Tag.ForTag.html
Iterates over a collection and displays a property for each item. See forloop object for available attributes.
```liquex
{% for product in collection.products %}
{{ product.title }}
{% endfor %}
```
--------------------------------
### Cycle through strings
Source: https://hexdocs.pm/liquex/Liquex.Tag.CycleTag.html
Demonstrates basic usage of the cycle tag to rotate through a list of strings.
```liquid
{% cycle "one", "two", "three" %}
{% cycle "one", "two", "three" %}
{% cycle "one", "two", "three" %}
{% cycle "one", "two", "three" %}
```
--------------------------------
### Liquex.Cache Callback: fetch/2
Source: https://hexdocs.pm/liquex/Liquex.Cache.html
Defines the fetch callback for retrieving values from the cache or executing a fallback function if the key is missing.
```APIDOC
## fetch(key, function)
### Description
Fetch a value from cache. If the value doesn't exist, run the given function and store the results within the cache.
### Signature
`@callback fetch(key(), (-> value())) :: value()`
### Parameters
- **key** (key()) - Required - The cache key to look up.
- **function** (function) - Required - A zero-arity function to execute if the key is not found in the cache.
```
--------------------------------
### IfTag Equivalent to UnlessTag in Liquex
Source: https://hexdocs.pm/liquex/Liquex.Tag.UnlessTag.html
Demonstrates the equivalent logic of the UnlessTag using the IfTag with a negation. This is useful for understanding conditional flow.
```liquex
{% if product.title != "Awesome Shoes" %}
These shoes are not awesome.
{% endif %}
```
--------------------------------
### Render Liquex AST
Source: https://hexdocs.pm/liquex/Liquex.html
Renders a parsed AST document with the provided context.
```elixir
@spec render!(document_t(), Liquex.Context.t() | map()) ::
{iodata(), Liquex.Context.t()}
```
--------------------------------
### Render another template in Liquex
Source: https://hexdocs.pm/liquex/Liquex.Tag.RenderTag.html
Use the `render` tag to insert the content of another template. Do not include the `.liquid` extension.
```liquid
{% render "template-name" %}
```
--------------------------------
### Create New Context
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Function specification for creating a new context with an environment map and optional configuration.
```elixir
@spec new(map(), Keyword.t()) :: t()
```
--------------------------------
### Liquex Core Modules
Source: https://hexdocs.pm/liquex/api-reference.html
Overview of the core modules within the Liquex library.
```APIDOC
## Liquex
A Liquid template parser for Elixir.
### Modules
* **Liquex.BlankFileSystem**: Default file system that throws an error when trying to call render within a template.
* **Liquex.Cache**: Caching behaviour attached to a `Liquex.Context`.
* **Liquex.Cache.DisabledCache**: Default caching system for Liquex. Always runs the given function and never stores the results.
* **Liquex.Cache.SimpleCache**: Basic caching system that uses ETS.
* **Liquex.Collection**: Represents collections in Liquid.
* **Liquex.Context**: Context keeps the variable stack and resolves variables, as well as keywords. It also keeps configuration information needed to render a Liquid template, such as filters and the file system.
* **Liquex.FileSystem**: Behaviour for file system access used by the `render` tag.
* **Liquex.Filter**: Contains all the basic filters for Liquid.
* **Liquex.LocalFileSystem**: Implements an abstract file system which retrieves template files named in a manner similar to liquid, ie. with the template name prefixed with an underscore. The extension ".liquid" is also added.
* **Liquex.Parser**: Liquid parser.
* **Liquex.Parser.Field**: Helper parsers for parsing fields.
* **Liquex.Parser.Literal**: Helper parsers for parsing literal values in Liquid.
* **Liquex.Parser.Object**: Helper methods for parsing object tags and arguments used by objects.
* **Liquex.Parser.Tag**: Helper methods for parsing tags.
* **Liquex.Represent**: Helper methods for maps.
* **Liquex.Representable**: Represents objects that can be rendered.
* **Liquex.Tag**: Behaviour for building a tag parser and renderer in Liquex.
```
--------------------------------
### Liquex.Tag.CaseTag Usage
Source: https://hexdocs.pm/liquex/Liquex.Tag.CaseTag.html
Documentation for the CaseTag implementation, including syntax and function signatures.
```APIDOC
## CaseTag Syntax
### Description
Creates a switch statement to execute a particular block of code when a variable has a specified value. The case tag initializes the switch, when defines conditions, and else provides a fallback.
### Request Example
{% assign handle = "cake" %}
{% case handle %}
{% when "cake" %}
This is a cake
{% when "cookie", "biscuit" %}
This is a cookie
{% else %}
This is not a cake nor a cookie
{% endcase %}
### Response Example
This is a cake
## Functions
### render(list, context)
- **Signature**: @spec render(list(), Liquex.Context.t()) :: Liquex.Render.result_t()
- **Description**: Callback implementation for Liquex.Tag.render/2.
```
--------------------------------
### Prepend String
Source: https://hexdocs.pm/liquex/Liquex.Filter.html
Prepends a string to the beginning of another string.
```APIDOC
## prepend(value, prepender, _)
### Description
Adds the specified string to the beginning of another string.
### Method
Filter
### Parameters
#### Path Parameters
- **value** (string) - Required - The string to prepend to.
- **prepender** (string) - Required - The string to prepend.
### Request Example
```liquid
{{ "World" | prepend: "Hello " }}
```
### Response
#### Success Response (200)
- **value** (string) - The resulting string after prepending.
#### Response Example
```json
{
"example": "Hello World"
}
```
```
--------------------------------
### Parse keyword fields with keyword_fields/1
Source: https://hexdocs.pm/liquex/Liquex.Parser.Object.html
Parses multiple keyword fields.
```elixir
@spec keyword_fields(NimbleParsec.t()) :: NimbleParsec.t()
```
--------------------------------
### new_isolated_subscope/2
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Creates a new context inheriting static environment and options.
```APIDOC
## new_isolated_subscope(context, environment)
### Description
Create a new context inheriting static environment and options.
### Parameters
- **context** (t()) - Required - The current context.
- **environment** (map()) - Optional - The environment map to inherit.
```
--------------------------------
### Define render/2 Callback
Source: https://hexdocs.pm/liquex/Liquex.Tag.html
Callback signature for rendering the tag built by the parser.
```elixir
@callback render(list(), Liquex.Context.t()) :: Liquex.Render.result_t()
```
--------------------------------
### Use LiquidTag for Concise Logic
Source: https://hexdocs.pm/liquex/Liquex.Tag.LiquidTag.html
Encloses multiple tags within one set of delimiters, to allow writing Liquid logic more concisely. Use 'echo' to output data as any tag blocks opened within a liquid tag must also be closed within the same tag.
```liquid
{% liquid
case section.blocks.size
when 1
assign column_size = ''
when 2
assign column_size = 'one-half'
when 3
assign column_size = 'one-third'
else
assign column_size = 'one-quarter'
endcase %}copy
```
--------------------------------
### First Item
Source: https://hexdocs.pm/liquex/Liquex.Filter.html
Returns the first item of an array.
```APIDOC
## first(list, _)
### Description
Returns the first item of an array.
### Method
Filter
### Parameters
#### Path Parameters
- **list** (array) - Required - The array to get the first item from.
### Request Example
```liquid
{{ [1, 2, 3] | first }}
```
### Response
#### Success Response (200)
- **item** (any) - The first item in the array.
#### Response Example
```json
{
"example": "1"
}
```
```
--------------------------------
### Liquex CycleTag with Cycle Groups
Source: https://hexdocs.pm/liquex/Liquex.Tag.CycleTag.html
Shows how to use cycle groups to manage multiple independent cycle blocks within a template.
```APIDOC
## POST /api/cycle/group
### Description
Accepts a 'cycle group' parameter in cases where you need multiple cycle blocks in one template. If no name is supplied for the cycle group, then it is assumed that multiple calls with the same parameters are one group.
### Method
POST
### Endpoint
/api/cycle/group
### Parameters
#### Request Body
- **group_name** (string) - Optional - The name of the cycle group.
- **strings** (array) - Required - An array of strings to cycle through.
### Request Example
```json
{
"group_name": "first",
"strings": ["one", "two", "three"]
}
```
### Response
#### Success Response (200)
- **output** (string) - The next string in the specified cycle group.
#### Response Example
```json
{
"output": "one"
}
```
```
--------------------------------
### open_tag
Source: https://hexdocs.pm/liquex/Liquex.Parser.Tag.html
Parses opening tags in the Liquex format.
```APIDOC
## open_tag(combinator \
empty())
### Description
Parse open tags
### Method
NIMBLEPARSEC
### Endpoint
N/A
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
NimbleParsec combinator
#### Response Example
```
* "{%"
* "{%-"copy
```
```
--------------------------------
### Output expressions with EchoTag
Source: https://hexdocs.pm/liquex/Liquex.Tag.EchoTag.html
Use the echo tag to output product titles with capitalization applied within a liquid loop.
```liquid
{% liquid
for product in collection.products
echo product.title | capitalize
endfor %}
```
--------------------------------
### At Least
Source: https://hexdocs.pm/liquex/Liquex.Filter.html
Sets a minimum value for a number.
```APIDOC
## at_least(value, max, _)
### Description
Sets a minimum value.
### Method
Filter
### Parameters
#### Path Parameters
- **value** (number) - Required - The input number.
- **max** (number) - Required - The minimum allowed value.
### Request Example
```liquid
{{ 5 | at_least: 10 }}
```
### Response
#### Success Response (200)
- **value** (number) - The value, ensuring it is at least `max`.
#### Response Example
```json
{
"example": "10"
}
```
```
--------------------------------
### pop/2
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Callback implementation for Access.pop/2 to remove a key from the context.
```APIDOC
## pop(context, key)
### Description
Callback implementation for Access.pop/2.
### Parameters
- **context** (t()) - Required - The current context.
- **key** (atom | binary) - Required - The key to pop.
```
--------------------------------
### parse/2
Source: https://hexdocs.pm/liquex/Liquex.html
Parses a liquid template string into a document AST.
```APIDOC
## parse(template, parser)
### Description
Parses a liquid template string using the given parser.
### Parameters
- **template** (String.t) - Required - The liquid template string.
- **parser** (module) - Optional - The parser module to use (defaults to Liquex.Parser.Base).
### Response
- **Success** ({:ok, document_t()}) - Returns the parsed AST document.
- **Error** ({:error, String.t(), pos_integer()}) - Returns an error message and position.
```
--------------------------------
### Liquex.Parser.Object Functions
Source: https://hexdocs.pm/liquex/Liquex.Parser.Object.html
A collection of parser functions for handling Liquid object syntax components.
```APIDOC
## arguments(combinator)
### Description
Parse arguments. Arguments are key/value pairs, but a key may have multiple values separated by commas.
### Parameters
#### Path Parameters
- **combinator** (NimbleParsec.t) - Optional - The base combinator to append to.
### Request Example
"img_url: '400x400', crop: 'bottom', filter: 'blur'"
---
## close_object_remove_whitespace(combinator)
### Description
Parses closing object tag with white space removing.
### Parameters
#### Path Parameters
- **combinator** (NimbleParsec.t) - Optional - The base combinator to append to.
### Request Example
"-}} "
---
## filter(combinator)
### Description
Parses filter that starts with a pipe.
### Parameters
#### Path Parameters
- **combinator** (NimbleParsec.t) - Optional - The base combinator to append to.
### Request Example
"| sort"
---
## keyword_field(combinator)
### Description
Parse keyword field.
### Parameters
#### Path Parameters
- **combinator** (NimbleParsec.t) - Required - The base combinator to append to.
### Request Example
"key: value"
---
## object(combinator)
### Description
Parses object. May contain arguments, literals, and filters. It special cases space removing tags such as `{{-` and `-}}` to properly remove any spaces leading and trailing spaces if requested.
### Parameters
#### Path Parameters
- **combinator** (NimbleParsec.t) - Optional - The base combinator to append to.
### Request Example
"{{ variable_a | at_most: 5 }}"
```
--------------------------------
### Convert and Map Object Keys to Strings with Liquex
Source: https://hexdocs.pm/liquex/Liquex.Represent.html
Use `represent/2` to convert any object, deeply mapping atom keys to strings. Set the `deep` argument to `false` to return a function for nested objects, allowing lazy evaluation.
```elixir
@spec represent(any(), boolean()) :: any()
```
--------------------------------
### Generate Full Template Path
Source: https://hexdocs.pm/liquex/Liquex.LocalFileSystem.html
Generates the full path for a given template path using the configured root path and pattern of the Liquex.LocalFileSystem instance. Template paths are restricted to letters, numbers, and underscores for security.
```elixir
iex> Liquex.LocalFileSystem.full_path(file_system, "mypartial")
```
--------------------------------
### Using Inline Comments in Liquid
Source: https://hexdocs.pm/liquex/Liquex.Tag.InlineCommentTag.html
Demonstrates how to use the # character for inline comments in both standard and liquid tag syntax.
```liquid
Nothing in the comments will be rendered.
{% # This is a comment and won't be rendered %}
{% liquid # This is also a comment and won't be rendered %}
```
--------------------------------
### Render template for each item in a collection using 'for' in Liquex
Source: https://hexdocs.pm/liquex/Liquex.Tag.RenderTag.html
Render a template once for each value in an enumerable object using the `for` parameter, optionally aliasing with `as`. The `forloop` object is accessible within the rendered template.
```liquid
{% assign variants = product.variants %}
{% render "product_variant" for variants as variant %}
```
--------------------------------
### Date and Default Filters
Source: https://hexdocs.pm/liquex/Liquex.Filter.html
Filters for date formatting and providing default values.
```APIDOC
## date(value, format, context)
### Description
Converts `value` timestamp into another date `format`. The format for this syntax is the same as strftime. The input uses the same format as Ruby’s Time.parse.
### Method
N/A (Filter Function)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```json
{
"example": "01/01/2000"
}
```
### Response
#### Success Response (200)
- **string** (string) - The formatted date string.
#### Response Example
```json
{
"example": "01/01/2000"
}
```
## default(value, def_value, _)
### Description
Allows you to specify a fallback in case a value doesn’t exist. `default` will show its value if the left side is nil, false, or empty.
### Method
N/A (Filter Function)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
```json
{
"example": "1.99"
}
```
### Response
#### Success Response (200)
- **string** (string) - The original value if it exists, otherwise the default value.
#### Response Example
```json
{
"example": "1.99"
}
```
```
--------------------------------
### new Function Signature
Source: https://hexdocs.pm/liquex/Liquex.LocalFileSystem.html
Specifies the function signature for `new`, indicating it takes a root path string and an optional pattern string, returning a LocalFileSystem struct.
```elixir
@spec new(String.t(), String.t()) :: t()
```
--------------------------------
### Liquex.Tag.RawTag Functions
Source: https://hexdocs.pm/liquex/Liquex.Tag.RawTag.html
Overview of the functions available in the Liquex.Tag.RawTag module.
```APIDOC
## Functions
### `parse()`
Callback implementation for `Liquex.Tag.parse/0`.
### `render(contents, context)`
Callback implementation for `Liquex.Tag.render/2`.
```
--------------------------------
### Prepend Filter
Source: https://hexdocs.pm/liquex/Liquex.Filter.html
Adds a string to the beginning of another string.
```elixir
iex> Liquex.Filter.prepend("apples, oranges, and bananas", "Some fruit: ", %{})
"Some fruit: apples, oranges, and bananas"
iex> Liquex.Filter.prepend("/index.html", "example.com", %{})
"example.com/index.html"
```
--------------------------------
### Nim callback for parsing Liquex tags
Source: https://hexdocs.pm/liquex/Liquex.Tag.RenderTag.html
Callback implementation for `Liquex.Tag.parse_liquid_tag/0`. This function handles the parsing of specific Liquex tags.
```nim
Callback implementation for `Liquex.Tag.parse_liquid_tag/0`.
```
--------------------------------
### Define a Custom Parser
Source: https://hexdocs.pm/liquex/Liquex.Tag.html
Register custom tags within a module using the Liquex.Parser macro.
```elixir
defmodule CustomParser do
use Liquex.Parser, tags: [CustomTag, OtherTag]
end
```
--------------------------------
### Liquex.Context.assign/3
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Assigns a new variable to the current context.
```APIDOC
## assign(context, key, value)
### Description
Set a variable named `key` with the given `value` in the current context.
### Parameters
#### Request Body
- **context** (t) - Required - The current context struct.
- **key** (String.t | atom) - Required - The variable name.
- **value** (any) - Required - The value to assign.
### Response
#### Success Response (200)
- **t()** (struct) - The updated context.
```
--------------------------------
### parse!/2
Source: https://hexdocs.pm/liquex/Liquex.html
Parses a liquid template string and returns the AST or raises an exception.
```APIDOC
## parse!(template, parser)
### Description
Pares a liquid template string and returns the AST or raises an exception.
### Parameters
- **template** (String.t) - Required - The liquid template string.
- **parser** (module) - Optional - The parser module to use (defaults to Liquex.Parser.Base).
### Response
- **Success** (document_t()) - Returns the parsed AST document.
- **Error** (no_return()) - Raises an exception on failure.
```
--------------------------------
### Capture String Content
Source: https://hexdocs.pm/liquex/Liquex.Tag.CaptureTag.html
Use capture to store the string inside the opening and closing tags into a variable. Variables created with capture are stored as strings.
```liquex
{% capture my_variable %}I am being captured.{% endcapture %}
{{ my_variable }}
```
--------------------------------
### Apply Module
Source: https://hexdocs.pm/liquex/Liquex.Filter.html
Applies a module to a value.
```APIDOC
## apply(mod __MODULE__, value, arg, context)
### Description
Applies a module to a value.
### Method
Filter
### Parameters
#### Path Parameters
- **mod __MODULE__** (module) - Required - The module to apply.
- **value** (any) - Required - The value to apply the module to.
- **arg** (any) - Optional - An argument for the module.
- **context** (object) - Optional - The context for the module application.
### Request Example
```liquid
{{ my_value | apply: my_module, my_arg }}
```
### Response
#### Success Response (200)
- **result** (any) - The result of applying the module.
#### Response Example
```json
{
"example": "result_of_module_application"
}
```
```
--------------------------------
### Render template with variables in Liquex
Source: https://hexdocs.pm/liquex/Liquex.Tag.RenderTag.html
Pass variables to a rendered template by listing them as parameters. Variables assigned in the parent template are not automatically available in the child, and vice-versa.
```liquid
{% assign my_variable = "apples" %}
{% render "name", my_variable: my_variable, my_other_variable: "oranges" %}
```
```liquid
{% assign featured_product = all_products["product_handle"] %}
{% render "product", product: featured_product %}
```
--------------------------------
### Create New Isolated Subscope
Source: https://hexdocs.pm/liquex/Liquex.Context.html
Creates a new context that inherits the static environment and options from the current context. Use this to establish a new, isolated scope for operations.
```elixir
@spec new_isolated_subscope(t(), map()) :: t()
```