Display conditions

For developersVersion 1.0.0Last updated:

Any section, container or widget of the builder supports the bosCond attribute (Builder_OS_Layout_Conditions, includes/layout/class-builder-os-layout-conditions.php; UI in builder-os-layout-dynamic.js, Advanced tab › Conditions). It’s evaluated on the server when rendering: if it doesn’t pass, nothing is output (no HTML, no styles, no children).

{ "action": "show" | "hide", "match": "all" | "any", "rules": [ { "type": "login", "value": "in" } ] }

action: “Show if” / “Hide if”. match: “All are met” / “Any is met”. Up to 12 rules (MAX_RULES); anything invalid is discarded, and with no valid rules the attribute is removed.

Type (type)LabelFields
loginSessionvalue: in | out
roleUser roleop: in | nin, values: roles
dateDatesfrom, to: YYYY-MM-DD or YYYY-MM-DDTHH:MM (site time zone; one is enough)
timeSchedulefrom, to: HH:MM (if from > to, it crosses midnight)
weekdayDay of the weekvalues: 1 to 7 (1 = Monday)
paramURL parameterkey, op: eq | neq | contains | empty | notempty, value
referrerReferring pageop: contains | ncontains, value
fieldDynamic datatag, key, op: eq | neq | contains | empty | notempty | gt | lt, value (text data only, and not visitor data)
post_typeContent typeop, values: types
postPost or pageop, values: IDs
termCategory or termtax, op, values: slugs
woo_stockProduct in stockvalue: yes | no (WooCommerce)
woo_saleProduct on salevalue: yes | no (WooCommerce)
cartCartvalue: notempty | empty
in_cartProduct in the cartvalues: product IDs (met if any is in the cart)
langLanguageop, values: codes (only with several languages)
  • Page cache: param, referrer, date, time and weekday (NO_CACHE) always set DONOTCACHEPAGE, because the cache ignores utm_* and the Referer and a saved copy would freeze the time. login, role, cart and in_cart (COOKIE) depend on the session or the cart: BuilderOS’s cache isn’t used with cookies and, if the request carries them, DONOTCACHEPAGE is set. The rest depends only on the content and can be cached. The editor warns “It depends on the visit or the time: this page won’t be cached.”
  • Preview as… (editor only): “Editor (everything visible),” “Logged-out visitor,” “Logged-in user” or “Role: …”; it hides on the canvas whatever that person wouldn’t see (session and role). Items with conditions carry a dotted border and the “Condition” label on the canvas.
  • REST: POST /builder-os/v1/layout/dynamic-preview (cfg, type, post_id; requires edit_posts) returns { value }: the preview of a datum with its format on the post being edited.
  • Filter: builder_os_conditions_now (the time used by date, time and weekday, for testing).