Display conditions
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) | Label | Fields |
|---|---|---|
login | Session | value: in | out |
role | User role | op: in | nin, values: roles |
date | Dates | from, to: YYYY-MM-DD or YYYY-MM-DDTHH:MM (site time zone; one is enough) |
time | Schedule | from, to: HH:MM (if from > to, it crosses midnight) |
weekday | Day of the week | values: 1 to 7 (1 = Monday) |
param | URL parameter | key, op: eq | neq | contains | empty | notempty, value |
referrer | Referring page | op: contains | ncontains, value |
field | Dynamic data | tag, key, op: eq | neq | contains | empty | notempty | gt | lt, value (text data only, and not visitor data) |
post_type | Content type | op, values: types |
post | Post or page | op, values: IDs |
term | Category or term | tax, op, values: slugs |
woo_stock | Product in stock | value: yes | no (WooCommerce) |
woo_sale | Product on sale | value: yes | no (WooCommerce) |
cart | Cart | value: notempty | empty |
in_cart | Product in the cart | values: product IDs (met if any is in the cart) |
lang | Language | op, values: codes (only with several languages) |
- Page cache:
param,referrer,date,timeandweekday(NO_CACHE) always setDONOTCACHEPAGE, because the cache ignoresutm_*and the Referer and a saved copy would freeze the time.login,role,cartandin_cart(COOKIE) depend on the session or the cart: BuilderOS’s cache isn’t used with cookies and, if the request carries them,DONOTCACHEPAGEis 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; requiresedit_posts) returns{ value }: the preview of a datum with its format on the post being edited. - Filter:
builder_os_conditions_now(the time used bydate,timeandweekday, for testing).