Data Attributes
Most of what a marketing site wants from Open Shop is small: hide the Login link when someone is signed in, print their first name, open the cart from a nav button. The data-os-* attributes do those without a line of JavaScript.
Add the attribute to your own HTML. The bundle reads it and acts, using the same JavaScript API underneath. Your site builder does nothing with these attributes beyond publishing them into the markup.
Example
Section titled “Example”<a href="/customer" data-os-show="guest">Login</a><a href="/customer" data-os-show="customer">Hi, <span data-os-text="customer.firstName"></span></a>
<span data-os-show="referral">Shopping with <span data-os-text="referral.firstName"></span></span><div data-os-hide="cart">Free shipping on your first order</div>
<a href="/assessment/" data-os-handoff>Take the Assessment</a><button data-os-cart-open>Cart (<span data-os-text="cart.itemCount">0</span>)</button><button data-os-add-to-cart="vip-perks">Subscribe</button>The attributes
Section titled “The attributes”| Attribute | Behaviour |
|---|---|
data-os-show="guest | customer | referral | cart" | Sets hidden on the element unless the state matches. cart means the cart holds at least one item. Comma-separated values are OR’d: data-os-show="customer,referral" shows for either. |
data-os-show="referral-entitlement:<CODE>" | Shows the element only when the resolved enroller holds that storefront entitlement. Combines with the values above. |
data-os-show="referral-branding" | Shows the element only when the resolved enroller has a rep-site section to show. Combines with the values above. |
data-os-hide="guest | customer | referral | cart" | The mirror of data-os-show: sets hidden when a listed state does match. Same values, including referral-entitlement:<CODE> and referral-branding, also OR’d. |
data-os-text="<key>" | Writes the value into the element’s textContent. Keys come from the whitelist below; anything else leaves the element untouched. |
data-os-src="referral.branding.photoUrl" | On an <img>, sets src to the rep’s photo. See data-os-src. |
data-os-handoff | On click, mints a handoff token and sends the shopper to the anchor’s href with ?token= appended. |
data-os-cart-open | On click, opens the cart slideout. |
data-os-cart-close | On click, closes the cart slideout. |
data-os-add-to-cart="<slug>" | On click, adds that product to the cart. Errors surface through the bundle’s own toasts. |
data-os-quantity="<number>" | Optional companion to data-os-add-to-cart. How many to add. |
data-os-auth="pending | guest | customer" | Set by the bundle on <html>, never by you. The CSS-only version of data-os-show. |
data-os-referral-entitlements="<CODES>" | Set by the bundle on <html>, never by you. The resolved enroller’s storefront entitlement codes, space-separated, for theming with CSS. |
data-os-show
Section titled “data-os-show”The pattern is a pair of elements, not one element that flips. Build both states in your design, mark each with the state it belongs to, and let Open Shop hide the wrong one.
<a href="/customer" data-os-show="guest">Login</a><a href="/account" data-os-show="customer">My Account</a>| Value | Shown when |
|---|---|
guest | Login state resolved and nobody is signed in. |
customer | Login state resolved and someone is signed in. |
referral | An enroller is resolved for this visit. |
referral-entitlement:<CODE> | An enroller is resolved and holds the storefront entitlement CODE. |
referral-branding | An enroller is resolved and has a rep-site section to show. |
cart | The cart holds at least one item. |
Neither login variant shows while login state is still resolving, so the nav does not flash the wrong link. See data-os-auth for styling that in-between moment yourself.
One moment the bundle cannot cover is the one before it runs: the browser can paint your markup as written before a deferred script executes, so on a slow first visit both links would appear for an instant. One line of site CSS closes that gap by hiding every data-os-show element until the bundle’s first paint, which is also when <html> first gets its data-os-auth attribute:
html:not([data-os-auth]) [data-os-show] { display: none;}A value the bundle does not recognise leaves the element exactly as you authored it, so a typo like data-os-show="custmer" shows the element rather than hiding it. Mistakes fail visible, never blank.
data-os-hide
Section titled “data-os-hide”The mirror of data-os-show. It takes the same values, comma-separated and OR’d, and hides the element when any listed state matches. When none match, the element shows.
<div data-os-hide="cart">Free shipping on your first order</div>| Value | Hidden when |
|---|---|
guest | Login state resolved and nobody is signed in. |
customer | Login state resolved and someone is signed in. |
referral | An enroller is resolved for this visit. |
referral-entitlement:<CODE> | An enroller is resolved and holds the storefront entitlement CODE. |
referral-branding | An enroller is resolved and has a rep-site section to show. |
cart | The cart holds at least one item. |
A value the bundle does not recognise leaves the element untouched, exactly as with data-os-show.
While login state is resolving
Section titled “While login state is resolving”guest and customer in a hide list match nothing until the customer resolves, so data-os-hide hides nothing on their account during that window. This is deliberately the opposite of data-os-show, which hides both variants while pending.
The practical consequence: a data-os-hide="customer" element starts visible and disappears once a signed-in shopper resolves. That is fine when a brief appearance is harmless, and wrong when it is not.
Which one to use
Section titled “Which one to use”Use data-os-show pairs for the login link. A hide-based nav would show the wrong link during the pending window — a signed-in shopper would see Login until their session resolved, which is the flash the pair pattern exists to prevent.
Use data-os-hide for content that should be visible by default and step aside once a state applies:
| Markup | What it does |
|---|---|
data-os-hide="cart" | Hides a promo banner once the cart has something in it. |
data-os-hide="referral" | Hides an enroller-finder block once an enroller is attached. |
data-os-hide="customer" | Hides a “create an account” nudge from signed-in shoppers. |
That last one is safe precisely because the pending window is harmless: a signed-in shopper may see the signup nudge for a moment before their login state resolves, which costs nothing. Apply the same test to your own case — if a brief appearance would be wrong, use a show pair instead.
The referral values follow the same rule. Until os-referral-tracker resolves the enroller, referral, referral-entitlement:<CODE>, and referral-branding in a hide list match nothing, so that content shows while the referral is pending. On a page without the tracker the referral never resolves, so it never hides.
referral-entitlement:CODE
Section titled “referral-entitlement:CODE”A store can mark an entitlement Show on storefront (Settings › Entitlements in the Open Shop admin). When the enroller the shopper is shopping with holds one of those entitlements, its code reaches the storefront, and referral-entitlement:<CODE> lets you show or hide content for it. Use it for a banner, a nav link, or a whole home-page section that only makes sense for one kind of rep.
<section data-os-show="referral-entitlement:BOATS">New boat inventory from your dealer</section><section data-os-show="referral-entitlement:CARS">Certified pre-owned cars</section><section data-os-hide="referral-entitlement:BOATS,referral-entitlement:CARS">Find a dealer near you</section>- The code is the entitlement’s Code in the admin, not its name. It is matched case-insensitively here, so
referral-entitlement:boatsworks too. - It mixes with the other values in one list:
data-os-show="referral-entitlement:BOATS,cart"shows for either. - Only entitlements switched to Show on storefront reach the browser. A code for any other entitlement never matches, even for a rep who holds it.
- It needs
os-referral-trackeron the page, because the tracker is what resolves the enroller.
Storefront entitlements walks through the whole setup, including products only those reps and their shoppers can buy.
Using both on one element
Section titled “Using both on one element”An element carrying both attributes is hidden if its show list fails or its hide list matches. Both tests must pass for it to show.
<div data-os-show="customer" data-os-hide="cart">Ready to reorder?</div>referral-branding
Section titled “referral-branding”Matches once the referral has resolved and the enroller has a rep-site section to show. It does not match when the store has rep sites off, the rep switched theirs off or never published one, or the store hid it.
Wrap everything bound to the rep’s section in one element carrying it, so the whole block disappears for shoppers without a rep, or with a rep who has nothing to show:
<section data-os-show="referral-branding">…the rep's photo, name, and paragraph…</section><section data-os-hide="referral-branding">Our story</section>Like the other referral values, it needs os-referral-tracker on the page, and in a hide list it matches nothing while the referral is pending, so the Our story fallback shows until then. See A rep section by hand for the full markup.
How hiding works
Section titled “How hiding works”Both data-os-show and data-os-hide hide an element the same way: the bundle sets the hidden attribute on it, and ships this rule inside its os-components cascade layer:
[data-os-show][hidden],[data-os-hide][hidden] { display: none !important;}That rule exists because hidden alone is fragile: any display value on the element overrides it, and site builders set one on almost every nav link. Webflow gives links display: flex or inline-block as a matter of course, which would otherwise un-hide them.
An !important declaration inside a cascade layer outranks everything in unlayered CSS — your normal rules and your !important ones, whatever their specificity. So the element stays hidden no matter what display your classes set. You do not need to do anything to make hiding work.
data-os-text
Section titled “data-os-text”Writes a single value into the element. The whole reachable surface is this whitelist — it is not a path evaluator, so customer.id or cart.items[0].name do nothing.
| Key | Value |
|---|---|
customer.firstName | Signed-in shopper’s given name. |
customer.lastName | Signed-in shopper’s family name. |
customer.accountTypeName | Their account type. |
customer.priceTypeName | Their price type. |
referral.firstName | Resolved enroller’s given name. |
referral.lastName | Resolved enroller’s family name. |
referral.displayName | The name the enroller sells under: their company, or their first and last name when none is set. |
referral.handle | Resolved enroller’s referral handle. |
referral.branding.paragraph | The paragraph from the enroller’s rep-site section. Set white-space: pre-line on the element so the rep’s line breaks show. Once the referral resolves without a paragraph the element is emptied, so a previous rep’s words never stay up. |
cart.itemCount | Number of items in the cart. |
cart.subtotal | Cart subtotal. |
store.name | The store’s name. |
Put a sensible fallback inside the element and it shows until the real value arrives:
<button data-os-cart-open>Cart (<span data-os-text="cart.itemCount">0</span>)</button>data-os-src
Section titled “data-os-src”Sets an image’s src from Open Shop data. It takes exactly one key:
| Key | Value |
|---|---|
referral.branding.photoUrl | The photo from the enroller’s rep-site section, already sized for display. |
<div data-os-show="referral-branding"> <img src="/images/rep-placeholder.jpg" alt="" data-os-src="referral.branding.photoUrl" /></div><img>only. On any other element the attribute is ignored.- Only
http:andhttps:URLs are applied. Anything else leaves the image as you wrote it. srcsetandsizesare removed when it binds. Site builders such as Webflow publish responsive images with them, and the browser would otherwise keep choosing fromsrcsetover the newsrc.- Your markup is the fallback. When there is no value — no referral, no section, no photo, or a referral change to a rep without one — the image gets back the
src,srcset, andsizesyou wrote, so a previous rep’s photo never lingers. Use thesrcas a placeholder.
Wrap the image in data-os-show="referral-branding" when the placeholder should not show at all without a rep.
A rep section by hand
Section titled “A rep section by hand”os-rep-spotlight renders a rep’s section for you. To use your own layout instead, bind each part and wrap them in referral-branding:
<section class="rep-section" data-os-show="referral-branding"> <img class="rep-photo" src="/images/rep-placeholder.jpg" alt="" data-os-src="referral.branding.photoUrl" /> <h2 data-os-text="referral.displayName"></h2> <p class="rep-paragraph" data-os-text="referral.branding.paragraph"></p></section>.rep-paragraph { white-space: pre-line;}The rep’s favorites are a list of products, which no binding can render. Use OpenShop.products.cards() with the slugs in branding.favorites, or place os-rep-spotlight for them.
data-os-handoff
Section titled “data-os-handoff”Put it on an anchor that points at another app your store hands shoppers off to. On click, Open Shop mints a handoff token and navigates to the href with ?token= appended, so the shopper does not sign in again.
<a href="/assessment/" data-os-handoff>Take the Assessment</a>The attribute needs no value — its presence is the switch.
It falls through to the plain href — the ordinary link, no token — whenever a token is not the right answer:
- The shopper is a guest.
- Minting the token fails.
- The click is a modified click (⌘, Ctrl, Shift, Alt) or a middle click, so “open in a new tab” keeps working.
target and the two click paths
Section titled “target and the two click paths”A shopper the bundle already knows is a guest is not intercepted at all — the browser follows the link natively, so target="_blank", rel, and every other link behaviour work exactly as authored.
For a signed-in shopper, and for anyone whose login state has not resolved yet, the bundle intercepts the click, mints the token, and then navigates in the same tab. target="_blank" is not honoured on that path. Do not rely on a handoff link opening a new tab: a guest would get one and a signed-in shopper would not.
Cart attributes
Section titled “Cart attributes”<button data-os-cart-open>Open cart</button><button data-os-cart-close>Keep shopping</button><button data-os-add-to-cart="vip-perks" data-os-quantity="2">Subscribe</button>data-os-cart-open and data-os-cart-close need os-cart-slideout on the page to have something to open.
data-os-add-to-cart takes the product slug. A successful add opens the cart slideout, the same as the components’ own add-to-cart buttons. Failures — an ineligible product, a duplicate enrollment — are reported by the bundle’s own toast, again the same way the product components report them. If you need to handle the failure yourself, call OpenShop.cart.add() instead and catch the error.
data-os-auth
Section titled “data-os-auth”The bundle sets data-os-auth on the <html> element and keeps it current. You never write it; you style against it.
| Value | Meaning |
|---|---|
pending | Login state has not resolved yet. |
guest | Resolved: nobody is signed in. |
customer | Resolved: a shopper is signed in. |
html[data-os-auth='customer'] .nav-login { display: none;}This is the CSS-only twin of data-os-show, and it is the tool for the in-between moment. Write the rules as “hide until the state that shows this is known” rather than matching pending: before the bundle has run at all, <html> carries no attribute, and :not() covers that window too.
html:not([data-os-auth='guest']) .nav-login,html:not([data-os-auth='customer']) .nav-account { visibility: hidden;}In practice pending is brief, and on repeat page views it is usually skipped entirely — the last known state is restored from the session cache before the request comes back.
data-os-referral-entitlements
Section titled “data-os-referral-entitlements”Once os-referral-tracker resolves the enroller, the bundle sets data-os-referral-entitlements on the <html> element to the codes of the storefront entitlements that enroller holds, separated by spaces. You never write it; you style against it.
<html data-os-referral-entitlements="BOATS CARS"></html>The attribute is removed when there is no referral, or when the enroller holds no storefront entitlements, so its absence means “no theme”. Match one code with ~=, which tests a single word in a space-separated list:
html[data-os-referral-entitlements~='BOATS'] .hero { background-image: url('/images/hero-boats.jpg');}
html[data-os-referral-entitlements~='CARS'] .hero { background-image: url('/images/hero-cars.jpg');}- Codes are uppercase, and the selector is case-sensitive. Write
~='BOATS', not~='boats'. This is the one place case matters;data-os-showignores it. - Use
~=, not=. An enroller can hold more than one code, and=only matches when the whole value is exactly that one code. - It is set in the browser. Until the tracker resolves the referral,
<html>has no attribute, so the first paint of a page uses your default styles and the theme lands a moment later. Design the default to look right on its own, and keep themed changes to things that can swap in without the page jumping, such as colours and images rather than layout. - It needs the tracker. Without
os-referral-trackeron the page the attribute never appears.
For anything CSS cannot express, read the same codes from OpenShop.referral.current.entitlements in a referral:change handler.
How bindings resolve
Section titled “How bindings resolve”- Clicks are delegated. One listener on
documenthandles every click attribute, so elements your own scripts insert later work with no extra setup. - Bindings are scanned at
ready, then again on everycustomer:change,cart:change, andreferral:change, and once more when the store overview resolves — that last pass is what fillsstore.name. Site-builder pages are static markup, so that covers them. If your code injectsdata-os-show,data-os-hide,data-os-text, ordata-os-srcmarkup after those events, nothing rescans it — call the JavaScript API directly for that content instead. - Values are written with
textContent. NeverinnerHTML. - Keys come from a whitelist. Unknown keys are ignored and leave the element exactly as you authored it.
Adding an attribute in Webflow
Section titled “Adding an attribute in Webflow”Webflow calls these custom attributes. They live on the element, not in an embed, so you can add them to links and buttons you already designed.
1 In the Webflow Designer, select the element you want to control — a nav link, a button, a text span.
2 Open the Element settings panel on the right (the gear icon above the Style panel).
3 Scroll to Custom attributes and click the +.
4 Type the attribute in Name and its value in Value, then press the checkmark to save:
| Goal | Name | Value |
|---|---|---|
| Show this link only to guests | data-os-show | guest |
| Show this link only to signed-in shoppers | data-os-show | customer |
| Hide this banner once the cart has items | data-os-hide | cart |
| Show this section for reps holding Boats | data-os-show | referral-entitlement:BOATS |
| Show this section only when the rep has one to show | data-os-show | referral-branding |
| Print the shopper’s first name | data-os-text | customer.firstName |
| Show the rep’s photo in this Image element | data-os-src | referral.branding.photoUrl |
| Open the cart from this button | data-os-cart-open | leave empty |
| Hand off a signed-in shopper | data-os-handoff | leave empty |
5 Repeat for each element, then Publish. Custom attributes only reach the page on a published site — the Designer canvas will not run them.
For a full walkthrough that puts this into a real nav, see Step 6 of the Webflow tutorial.