Files
webstudio/docs/university/foundations/expression-editor.md
T
Oleg Isonen f1c3abf1be docs: Refresh accessible Builder screenshots at 2x (#6595)
## Outcome

Refresh the accessible low-resolution Builder documentation screenshots
with current, native 2× light and dark captures. Images retain useful
crops, descriptive alt text, and explicit display widths.

The final audit accounts for 165 candidate files: 132 refreshed, 29
inaccessible screenshots kept with the user's approval, two existing
images made 2× by setting their display width, and two Content Engine
query screenshots held because the current Builder shows a false
draft-filter type warning. Those two originals remain in place pending a
separate Builder fix and recapture. Four animated GIFs remain outside
this still-screenshot refresh.

## Review checklist

- [x] Inventory image references, native dimensions, display widths, UI
states, and source pages; audit omitted references across all docs.
- [x] Replace the approved Form pairs and accessible Builder screenshots
with matching 2× light and dark captures.
- [x] Keep inaccessible external/account/desktop and disabled Export
images, as approved.
- [x] Review size-sufficient images and GIF/diagram exclusions.
- [x] Review crops, alt text, widths, links, and source references.
Independent screenshot review passed.
- [x] Check the full docs image inventory: 322 placements, 284 unique
assets, zero missing files. The only unaccounted sub-2× refs are four
excluded GIFs.
- [x] Run `git diff --check` and verify all 204 changed image files are
referenced; 117 changed picture placements have matching themes and at
least 2× native width.
- [x] Verify required PR checks: Lint PR, Check submodules, Visual
regression, and Main workflow all passed at 14937127db.
- [ ] Recapture the two Content Engine query images after [Builder fix
#6597](https://github.com/webstudio-is/webstudio/pull/6597) reaches the
Builder used for capture. Keep their originals until then.\n- [ ]
Confirm GitBook rendering at intended CSS widths after publication. This
repository has no PR preview.

## Held images

`content-engine-overview-query.png` and
`content-engine-article-query.png` are unchanged. The current Builder's
query form reports a false type warning for the Boolean
`properties.draft` filter. Screenshotting that state would teach a
broken workflow. The user approved a separate [Builder query type fix in
PR #6597](https://github.com/webstudio-is/webstudio/pull/6597). Once
that fix is reviewed, the two screenshots can be recaptured from the
corrected UI. This PR does not change application code.

All captures use synthetic content. No release or publication branch is
changed.
2026-10-25 10:11:58 +01:00

7.3 KiB
Raw Blame History

description
description
Create logical expressions directly in the UI, enabling conditional display, fallback values, concatenation, and more.

➕ Expression editor

Heading Text Content binding to the demo post title

Expression editor is available on every field when clicking the “+” button.

Most commonly used with Resources, Expression editor has two primary features:

  1. Binding (or “connecting”) external data to Webstudio fields. For example, connecting a blog’s featured image that exists in a headless CMS to the Image component in Webstudio.
  2. Running logical expressions such as concatenating two or more values or conditionally displaying a section.

{% hint style="info" %} Hint: Expand Expression editor to work within a larger window. {% endhint %}

Binding

Binding is when you “connect” or “map” various values to fields within Webstudio. For example, when creating a Dynamic Page for a blog, only one page exists in Webstudio, but the values within that page dynamically change based on the URL viewed. The dynamic aspect is enabled by binding the various CMS fields to Webstudio components.

You will see Variables within the Expression editor. You can click on the variable or type it in to bind its value to the field. But many times, the value you are looking for is a child within the variable.

Take, for example, the value of a custom Variable called CMS Data:

{
  "title": "Hello World",
  "slug": "hello-world",
  "image": {
    "url": "<https://example.com/image.png>",
    "alt": "I'm an image"
  }
}

If you wanted to bind the title of the post to a header component, you need to do more than click on the “CMS Data” Variable. You need to “drill down” or access the children of the variable. This is simply done by typing a . after the Variable, which will show the children in the autocomplete (i.e., title, slug, and image). For the title, you would enter CMS Data.title, and the value “Hello World” would display. When viewing a different post, that post’s title would display.

For the image URL, you would type CMS Data.image.url .

Expressions

Expression editor supports a simple subset of JavaScript, giving users a simple syntax without the footguns a complex programming language brings.

The following JavaScript expressions are supported:

  • Ternary operator – Useful for conditions such as “If the image is in my CMS, display it, otherwise hide it.” The actual expression for this would look something like CMS Data.image ? true : false and be bound to the “Show” field.
  • Template literals – Useful for inserting dynamic values inside templated text. For example, if you wanted to have “Updated On <insert dynamic data>”, it would look like `Updated On ${CMS Data.updatedOn}`. Note the Expression starts and ends with backticks, and the dynamic values are within ${}.
  • Expressions and operators – Useful for concatenating two values (alternative solution to template literals). For example, "Updated on " + CMS Data.updatedOn.
  • Safe string methods: at, split, replace, slice, startsWith, endsWith, includes, toLowerCase, toUpperCase, toLocaleLowerCase, toLocaleUpperCase
  • Safe array methods: at, includes, join, slice

Example expressions

Schema

You can create a schema and bind your CMS data to it. The schema can go in the head or body. Add an HTML Embed, create a binding, and use the following expression. Be sure to change out the schema type and variables with your data.

`<script type="application/ld+json">
    {
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "${YOUR.CMS.TITLE}",
  "image": [
    "${YOUR.CMS.LOGO_URL}"
  ],
  "datePublished": "${YOUR.CMS.PUBLISHED_DATE}",
  "dateModified": "${YOUR.CMS.MODIFIED_DATE}",
  "author": [
    {
      "@type": "Person",
      "name": "${YOUR.CMS.AUTHOR_NAME}",
      "url": "${YOUR.CMS.AUTHOR_URL}"
    }
  ]
}
</script>`;

Conditional collection items

Sometimes we need to conditionally hide some records in a Collection based on some context. For example, below a blog post we can have related blog posts, but we wouldn’t want to show the current blog post in there. To do so, create an expression on the Show property in Settings.

We need to turn this statement into code: “If the current page’s slug is the same as the current collection’s slug, then don’t show this post.”

Here is the expression. Be sure to modify it with your variables.

system.params.slug === collectionItem.slug ? false : true;

Again, be sure to change slug to your dynamic path parameter and collectionItem.slug to your Collection variable and its data.

This expression will now show “false” meaning “turn this off” if the related blog post is actually the same as the current blog post.

  • Variables – Define and use data throughout your pages
  • CMS – Connect to external content management systems
  • Dynamic 404 handling – Return 404 when CMS data is missing on a dynamic page
  • Collection – Iterate over data to create dynamic lists
  • HTML Embed – Embed custom HTML and scripts