Skip to content
Help Center
Submit a request Sign in

Liquid variables: use assign and capture without changing records

Local variables make a portal template easier to read and avoid repeating the same presentation expression. Use assign to give a value a name, and capture to build a string from a block. These variables exist for template rendering; they do not save a case field, change a contact or create an administrative setting.

At a glance

For: portal administrators and designers, including people new to Liquid. Applies to: Supportbench Core.

Start here: Settings → Customer Portal → select the portal → Page templates

Start with the practical purpose  ·  Syntax and supported behavior  ·  Example: keep a heading and explanation consistent  ·  Decide whether a captured string is text or markup  ·  Understand existing increment/decrement tags  ·  Apply the example in a working portal page  ·  Troubleshoot the common mistakes  ·  Keep the customization understandable

Start with the practical purpose

A local variable is a temporary name for a value while the page renders. For example, you can choose a heading label once and print it in several places. Give it a clear name that does not hide a supplied object such as sb or a loop row.

Use quotes for text. Write true or false without quotes for booleans. The text "false" is a nonempty string, so it is truthy in a condition; it is not the boolean false.

Syntax and supported behavior

TagBehavior
{% assign label = "Your requests" %}Assigns a text value to label.
{% assign show_summary = true %}Assigns a boolean value.
{% assign titles = sb.container.articles | map: "title" %}Assigns the result of a filter expression; the source collection must exist in the page context.
{% capture greeting %}…{% endcapture %}Captures the rendered block as a string. Whitespace inside the block becomes part of the captured string.

Example: keep a heading and explanation consistent

{% assign request_heading = "Your support requests" %}
{% capture request_intro %}Open a request below to read its available history and next steps.{% endcapture %}
<h1>{{ request_heading | escape }}</h1>
<p>{{ request_intro | strip | escape }}</p>

The labels in this example are presentation text, not new Supportbench configuration fields. For a multilingual portal, use the configured localization filters instead of assuming hard-coded English is appropriate for every language.

Decide whether a captured string is text or markup

Capture can include dynamic output and HTML, but it does not sanitize either. For a plain-text sentence, escape the final captured output. If capturing a deliberately constructed HTML fragment, escape the individual untrusted text values when building it and keep the markup under your control. Do not mix these approaches accidentally.

A captured number is a string. If you need arithmetic, keep a numeric assign/filter expression instead of assuming capture preserves numeric type.

Understand existing increment/decrement tags

The installed DotLiquid package recognizes increment and decrement for render-time counters. They use a separate counter mechanism from assign/capture; an identically named assigned variable is not updated by those tags. They are not advertised starter tags in the current designer. Preserve and test an existing use, but prefer a clear loop or local assign expression for a new simple presentation task.

None of these tags persists a counter to a customer record or provides a unique case number. Use Supportbench’s native record identifiers for that purpose.

Apply the example in a working portal page

  1. Open the intended portal’s Page templates with permission to administer communities or the applicable edit override. Choose the page that supplies the object used by your example.
  2. Preserve a copy of the existing template in your change record. Keep the working forms, routes, input names and script hooks; these examples change presentation.
  3. Make the smallest useful edit, then choose Save Changes → Design. Inspect populated, empty and signed-out preview states as relevant.
  4. Check punctuation, long text, optional values and narrow-screen layout. Confirm the result says what you intend, not merely that it renders.
  5. Use Review changes → Publish for the approved design. Then verify the actual portal as the intended customer and check the full task.

Designer preview data is synthetic. A successful preview confirms neither real customer access nor the effect of a server-side workflow. Liquid cannot grant permission, edit a case or fetch arbitrary database records.

Troubleshoot the common mistakes

ProblemCorrection
A condition behaves as true for "false"Remove quotes when you intend a boolean, or explicitly compare text when text is intended.
The heading contains extra whitespaceCapture includes whitespace; use strip for a text value or keep the captured block concise.
A variable changes nothing in the saved caseExpected. Liquid variables only affect rendering.
An existing counter does not update an assign variableThe counter mechanism is separate; do not rely on a shared name.

Keep the customization understandable

Use local variables to explain the presentation, not to recreate business rules. Keep record updates in the supported page actions and configuration workflows.

Use descriptive local variable names and keep conditions close to the content they control. Record the customer scenario tested when publishing a change. Recheck the template when its source fields, portal role rules or supported language behavior changes.

Was this article helpful?