Dynamic content: props of a block bound to fields of a record.
A node keeps its bindings next to its props, one per bound prop:
%{
"type" => "heading",
"props" => %{"text" => "Product name"},
"dynamic" => %{
"text" => %{"field" => "name"}
}
}When the node is rendered with a current item (inside a Loop grid, or a
document rendered with record=), the value of the field replaces the prop;
without one the prop keeps its own value, which works as a placeholder. Bound
values are cast and sanitized like any other value of the prop, so a field
can never inject markup or unsafe URLs.
A binding
"field"- the key of a field of the source ("name","category.name") or"@url"(the page of the item)"from"-"item"(default: the current item) or"site"(a top-level value of thedatathe host passes, such as the site name)"before"/"after"- text around the value ("$"," left")"fallback"- used when the item has no value"format"-"number"(thousands separators of the language, with"decimals"),"date","datetime","time","excerpt"(plain text cut to"length"characters),"upper"or"lower"
Only fields declared by the source can be read: a binding to anything else renders nothing.
Display conditions
A node can also be shown only for the items that match a condition on one of
their fields (its Advanced attribute "condition"): a Sold out badge
for products without stock, a Featured ribbon…
"attrs" => %{"condition" => %{"field" => "stock", "op" => "lte", "value" => "0"}}The operators are those of the filters of a loop (see
ElementorexCms.Source.Query). Without a current item the node is shown;
on the canvas, nodes whose condition fails are dimmed instead of removed.
Summary
Functions
Whether a prop can be bound to a field (lists cannot).
The binding of a prop of a node, or nil.
The text of a value for a binding: formatted per its "format" and the
current locale, "" for no value.
The raw value of a binding for the current item of ctx: {:ok, value, field} or :none when there is nothing to read from.
The source whose fields the :field props of a node choose from: its own
source prop (a loop) or, for a node in a filter form (a block with a
:loop prop, or inside one), the source of the loop grid it filters.
A date, date-time or time in the format of the current locale (kind is
:date, :datetime or :time). Times of a DateTime are shown in the
configured :time_zone when there is a time zone database.
A number with the thousands and decimal separators of the current locale.
decimals fixes the decimal places (rounding); nil keeps them.
Formats of a binding (see the module docs).
The source of the items a node is rendered with: the source of its nearest
enclosing loop, or document_source (the source of a template for single
records) when it is in no loop. nil when there is none.
Whether a node repeats its children for the items of a source (a loop block).
Keeps the valid bindings of a node: of props of block that can be bound
(any well-formed key when the block is unknown), with valid settings.
A valid binding or nil. Takes a map (string or atom keys), a keyword list
or just the field key.
A valid display condition or nil: "field" (like a binding's), "op"
(an operator of ElementorexCms.Source.Query), "value" and optionally
"from" => "site".
The settings of a binding (everything but the field): before, after,
fallback, format, decimals and length, validated.
The props of node with its bindings applied for the current item of ctx
(an ElementorexCms.Renderer.Context). Bindings without a value to read (no
current item) keep the prop's own value.
Fields for the site values of data (from: "site" bindings).
A top-level value of data (atom or string key) that can be shown: text,
numbers, booleans and dates. Anything else (structs, maps, lists) is not
readable from documents.
Turns a raw value into the value of prop: numbers for number props, true
or false for booleans, escaped text (paragraphs for rich text) and the
formatted text with before, after and fallback for the rest. The result
is cast again by the prop when the block renders.
Whether a node is shown for the current item of ctx: true without a
condition or without an item to check it against.
Functions
@spec bindable?(ElementorexCms.Block.Prop.t()) :: boolean()
Whether a prop can be bound to a field (lists cannot).
The binding of a prop of a node, or nil.
@spec display(term(), ElementorexCms.Source.Field.t() | nil, map()) :: String.t()
The text of a value for a binding: formatted per its "format" and the
current locale, "" for no value.
@spec fetch(map(), map()) :: {:ok, term(), ElementorexCms.Source.Field.t() | nil} | :none
The raw value of a binding for the current item of ctx: {:ok, value, field} or :none when there is nothing to read from.
@spec field_source( ElementorexCms.Document.t(), String.t() | nil, ElementorexCms.Sources.t(), ElementorexCms.Registry.t() | nil ) :: ElementorexCms.Source.t() | nil
The source whose fields the :field props of a node choose from: its own
source prop (a loop) or, for a node in a filter form (a block with a
:loop prop, or inside one), the source of the loop grid it filters.
A date, date-time or time in the format of the current locale (kind is
:date, :datetime or :time). Times of a DateTime are shown in the
configured :time_zone when there is a time zone database.
@spec format_number(term(), non_neg_integer() | nil) :: String.t()
A number with the thousands and decimal separators of the current locale.
decimals fixes the decimal places (rounding); nil keeps them.
iex> ElementorexCms.Dynamic.format_number(1234567.891, 2)
"1,234,567.89"
iex> ElementorexCms.I18n.with_locale("es", fn -> ElementorexCms.Dynamic.format_number(19990, 0) end)
"19.990"
@spec formats() :: [String.t()]
Formats of a binding (see the module docs).
@spec item_source( ElementorexCms.Document.t(), String.t() | nil, ElementorexCms.Sources.t(), String.t() | nil, ElementorexCms.Registry.t() | nil ) :: ElementorexCms.Source.t() | nil
The source of the items a node is rendered with: the source of its nearest
enclosing loop, or document_source (the source of a template for single
records) when it is in no loop. nil when there is none.
@spec loop?(map(), ElementorexCms.Registry.t() | nil) :: boolean()
Whether a node repeats its children for the items of a source (a loop block).
Keeps the valid bindings of a node: of props of block that can be bound
(any well-formed key when the block is unknown), with valid settings.
A valid binding or nil. Takes a map (string or atom keys), a keyword list
or just the field key.
iex> ElementorexCms.Dynamic.normalize_binding(field: "price", before: "$", format: "number")
%{"field" => "price", "before" => "$", "format" => "number"}
A valid display condition or nil: "field" (like a binding's), "op"
(an operator of ElementorexCms.Source.Query), "value" and optionally
"from" => "site".
The settings of a binding (everything but the field): before, after,
fallback, format, decimals and length, validated.
The props of node with its bindings applied for the current item of ctx
(an ElementorexCms.Renderer.Context). Bindings without a value to read (no
current item) keep the prop's own value.
@spec site_fields(term()) :: [ElementorexCms.Source.Field.t()]
Fields for the site values of data (from: "site" bindings).
A top-level value of data (atom or string key) that can be shown: text,
numbers, booleans and dates. Anything else (structs, maps, lists) is not
readable from documents.
@spec to_prop( term(), ElementorexCms.Source.Field.t() | nil, map(), ElementorexCms.Block.Prop.t() ) :: term()
Turns a raw value into the value of prop: numbers for number props, true
or false for booleans, escaped text (paragraphs for rich text) and the
formatted text with before, after and fallback for the rest. The result
is cast again by the prop when the block renders.
Whether a node is shown for the current item of ctx: true without a
condition or without an item to check it against.