DocsState & inputs · FQL
On this page

Derive display values

Use fallbacks, operators and formatter functions.

Before you begin: Keep data live.

Fallback Expressions

Use || for a truthy fallback and ?? when only null or undefined should fall back.

FQL state configuration

Add this configuration inside your page’s {STATE} declaration. Inspect state shows its configuration; live queries and saved data run against your local site. Try a complete FQL page →

|| is different from comma-separated value sources.

SyntaxPurpose
CommaMultiple events can write to the same state key.
||Returns the first truthy value, or the last value.
??Falls back only when the left value is null or undefined.

Use commas for "these are possible sources for this state." Use || for ordinary display fallbacks and ?? when false, 0, or an empty string must be preserved.

Logical AND with &&

Use && when one value should depend on another value being truthy.

FQL state configuration

Add this configuration inside your page’s {STATE} declaration. Inspect state shows its configuration; live queries and saved data run against your local site. Try a complete FQL page →

&& evaluates from left to right. It returns the first falsy value it finds. If every value is truthy, it returns the last value. It has higher precedence than ||, so this:

FQL state configuration

Add this configuration inside your page’s {STATE} declaration. Inspect state shows its configuration; live queries and saved data run against your local site. Try a complete FQL page →

is read like:

FQL state configuration

Add this configuration inside your page’s {STATE} declaration. Inspect state shows its configuration; live queries and saved data run against your local site. Try a complete FQL page →

Use && for truthy gating. Parentheses can make a longer expression's intent explicit.

Operators

FQL supports arithmetic (+, -, *, /, %), comparisons (==, !=, >, >=, <, <=), unary operators (!, unary +, unary -), &&, ||, ??, parentheses, and conditional expressions.

FQL state configuration

Add this configuration inside your page’s {STATE} declaration. Inspect state shows its configuration; live queries and saved data run against your local site. Try a complete FQL page →

== and != are type-strict in FQL: 1 == '1' is false.

Use parentheses when ?? appears in the same expression as || or &&. That keeps fallbacks readable and avoids relying on precedence in a line another theme developer may scan quickly.

Formatter and Event Functions

Functions used in FQL must be registered explicitly before Frontbacked.init().

index.html

Use functions after a path segment:

FQL state configuration

Add this configuration inside your page’s {STATE} declaration. Inspect state shows its configuration; live queries and saved data run against your local site. Try a complete FQL page →

The resolved value before .functionName(...) is always the first argument. The expressions written inside the parentheses are resolved and passed after it. FQL never adds a hidden surrounding list item; pass $ explicitly when a formatter needs the complete current record:

index.html

Custom function names must be single JavaScript-style identifiers. Built-in functions cannot be replaced or removed.

For event bindings, the first argument is the selected event value. For a binding like #termsButton.onclick.target.invertTermsClick(), the function can ignore the passed target and return a computed value.

You can pass a value through multiple functions before it is written to state. In #categories.onchange.target.value.load().post().parseResponse(), Frontbacked reads event.target.value, calls load(value), passes that result into post(...), then passes that result into parseResponse(...). The final return value becomes the state value.

Continue with Read and update state.