Skip to content

State & Conditional Attributes

State attributes enable conditional logic and visibility control without JavaScript.

  • Declarative Conditions: Express logic directly in HTML
  • CSS-Based Performance: Uses classes for visibility, not DOM manipulation
  • Real-Time Evaluation: Conditions re-evaluate on every state change
  • Layout Stability: No content shifting or reflow

Show elements when conditions are true.

<!-- Simple boolean conditions -->
<div data-next-show="cart.hasItems">
Cart has items
</div>
<div data-next-show="cart.isEmpty">
Cart is empty
</div>
<!-- Comparison operators -->
<div data-next-show="cart.total > 100">
Free shipping unlocked!
</div>
<div data-next-show="cart.totalQuantity >= 3">
Bulk discount applied
</div>
<!-- Complex expressions -->
<div data-next-show="cart.total > 50 && cart.totalQuantity < 10">
Eligible for express checkout
</div>
<!-- Function calls -->
<div data-next-show="cart.hasItem(123)">
Premium package selected
</div>

Hide elements when conditions are true (inverse of show).

<!-- Hide when cart is empty -->
<button data-next-hide="cart.isEmpty">
Proceed to Checkout
</button>
<!-- Hide when item in cart -->
<button data-next-hide="cart.hasItem(123)">
Add Premium Package
</button>
<!-- Hide below threshold -->
<div data-next-hide="cart.total < 25">
Checkout available
</div>

Show/hide content based on active customer profiles.

<!-- Show for specific profile -->
<div data-next-show-if-profile="premium">
Premium member exclusive pricing
</div>
<!-- Show for multiple profiles -->
<div data-next-show-if-profile="vip,premium,gold">
Member benefits apply
</div>
<!-- A/B testing -->
<div data-next-show-if-profile="control">
Standard pricing: $99
</div>
<div data-next-show-if-profile="test">
Special offer: $89
</div>
<!-- Hide from specific profiles -->
<div data-next-hide-if-profile="premium">
Upgrade to premium for better prices
</div>
<!-- Hide upgrade prompts from members -->
<div data-next-hide-if-profile="vip,premium">
<button>Become a Member</button>
</div>

The SDK automatically applies CSS classes based on element state.

ClassApplied WhenUsed On
.next-in-cartItem is in cartAction buttons
.next-cart-emptyCart has no itemsBody element
.next-cart-has-itemsCart has itemsBody element
/* Style based on cart state */
.next-in-cart {
background: green;
color: white;
}
.next-cart-empty .checkout-button {
opacity: 0.5;
pointer-events: none;
}
ClassApplied WhenUsed On
.next-loadingAction in progressAction elements
.next-disabledElement disabledInteractive elements
.next-activeElement is activeToggle elements
/* Loading state */
.next-loading {
opacity: 0.6;
cursor: wait;
}
/* Disabled state */
.next-disabled {
opacity: 0.4;
pointer-events: none;
}
ClassApplied WhenUsed On
.next-selectedOption selectedSelector options
.next-selector-activeHas active selectionSelector container
/* Selected option */
.next-selected {
border: 2px solid blue;
background: #f0f8ff;
}
/* Active selector */
.next-selector-active .default-message {
display: none;
}
ClassApplied WhenUsed On
.next-profile-[id]Profile is activeBody element
.next-profile-activeAny profile activeProfile elements
/* Profile-specific styles */
.next-profile-premium .price {
color: gold;
}
.next-profile-test .cta-button {
background: orange;
}
OperatorDescriptionExample
===Strict equalitycart.total === 100
!==Not equalprofile.active !== 'premium'
>Greater thancart.totalQuantity > 5
<Less thancart.total < 50
>=Greater or equalcart.items.length >= 3
<=Less or equalcart.discount <= 10
&&Logical ANDcart.hasItems && cart.total > 100
``
!Logical NOT!cart.hasItem(123)

Combine multiple conditions using logical operators for powerful conditional logic.

Show elements when ANY condition is true:

<!-- Show if cart has either package -->
<div data-next-show="cart.hasItem(15) || cart.hasItem(3)">
You have selected an eligible package!
</div>
<!-- Multiple OR conditions -->
<div data-next-show="cart.hasItem(10) || cart.hasItem(15) || cart.hasItem(20)">
Premium package detected
</div>
<!-- Combine with comparisons -->
<div data-next-show="cart.total > 100 || cart.totalQuantity > 5">
Eligible for bulk discount
</div>

Show elements when ALL conditions are true:

<!-- Both conditions must be met -->
<div data-next-show="cart.hasItem(15) && cart.total > 50">
Premium package with minimum order met
</div>
<!-- Multiple AND conditions -->
<div data-next-show="cart.hasItems && cart.totalQuantity > 2 && cart.total > 30">
Bulk order discount applied
</div>

Negate conditions:

<!-- Show when item is NOT in cart -->
<div data-next-show="!cart.hasItem(6)">
<button data-next-action="add-to-cart" data-next-package-id="6">
Add Extended Warranty
</button>
</div>
<!-- Combine with other operators -->
<div data-next-show="cart.hasItems && !cart.hasItem(123)">
Complete your order with our premium package
</div>

Control operator precedence with parentheses:

<!-- OR conditions grouped with AND -->
<div data-next-show="(cart.hasItem(15) || cart.hasItem(3)) && cart.total > 50">
Special offer unlocked!
</div>
<!-- Complex eligibility check -->
<div data-next-show="cart.hasItem(15) && (cart.total > 100 || cart.totalQuantity > 3)">
VIP checkout available
</div>
<!-- Multiple grouped conditions -->
<div data-next-show="(cart.hasItem(2) || cart.hasItem(3) || cart.hasItem(4)) && !cart.hasItem(6)">
Protect your purchase with extended warranty
</div>

Conditional Upsells

<!-- Show warranty upsell if main product in cart but warranty is not -->
<div data-next-show="(cart.hasItem(2) || cart.hasItem(3) || cart.hasItem(4) || cart.hasItem(5)) && !cart.hasItem(6)">
<div class="upsell-card">
<h3>Protect Your Purchase</h3>
<p>Add 3-year extended warranty for peace of mind</p>
<button data-next-action="add-to-cart" data-next-package-id="6">
Add Warranty - $29.99
</button>
</div>
</div>

Smart Cross-Sells

<!-- Show accessory bundle if user has product A or B, but not the accessory -->
<div data-next-show="(cart.hasItem(100) || cart.hasItem(101)) && !cart.hasItem(200)">
Complete your setup with our accessory bundle!
</div>

Eligibility Gates

<!-- Show express checkout only for qualified orders -->
<div data-next-show="cart.total > 25 && cart.total < 500 && cart.hasItems">
<button data-next-action="express-checkout">
Express Checkout Available
</button>
</div>
<!-- Boolean properties -->
<div data-next-show="cart.isEmpty">...</div>
<div data-next-show="cart.hasItems">...</div>
<div data-next-show="cart.hasDiscount">...</div>
<div data-next-show="cart.hasShipping">...</div>
<!-- Numeric properties -->
<div data-next-show="cart.total > 0">...</div>
<div data-next-show="cart.subtotal > 0">...</div>
<div data-next-show="cart.totalQuantity > 0">...</div>
<div data-next-show="cart.itemCount > 0">...</div>
<div data-next-show="cart.discount > 0">...</div>
<div data-next-show="cart.shipping > 0">...</div>
<!-- Functions -->
<div data-next-show="cart.hasItem(123)">...</div>
<div data-next-show="cart.hasPackage(123)">...</div>
<!-- Check package properties -->
<div data-next-show="package.123.inStock">...</div>
<div data-next-show="package.123.hasDiscount">...</div>
<div data-next-show="package.123.quantity > 0">...</div>
<div data-next-show="package.123.price < 100">...</div>
<!-- Order state checks -->
<div data-next-show="order.exists">...</div>
<div data-next-show="order.completed">...</div>
<div data-next-show="order.total > 0">...</div>
<div data-next-show="order.hasUpsells">...</div>
<!-- Profile checks -->
<div data-next-show="profile.active === 'premium'">...</div>
<div data-next-show="profile.is('vip')">...</div>
<div data-next-show="profile.exists">...</div>
<!-- Disabled until minimum met -->
<button
data-next-action="checkout"
data-next-show="cart.total >= 25"
disabled>
Checkout (Minimum $25)
</button>
<!-- Alternative message -->
<div data-next-show="cart.total < 25">
Add $<span data-next-display="25 - cart.total">0</span> more to checkout
</div>
<!-- Different messages based on cart value -->
<div data-next-show="cart.total === 0">
Your cart is empty
</div>
<div data-next-show="cart.total > 0 && cart.total < 50">
Add $<span data-next-display="50 - cart.total">0</span> for free shipping
</div>
<div data-next-show="cart.total >= 50 && cart.total < 100">
Free shipping unlocked! Add $<span data-next-display="100 - cart.total">0</span> for a gift
</div>
<div data-next-show="cart.total >= 100">
Free shipping + gift included!
</div>
<!-- Show complementary products based on cart -->
<div data-next-show="cart.hasItem(123) && !cart.hasItem(456)">
<h3>Complete your set</h3>
<button data-next-action="add-to-cart" data-next-package-id="456">
Add matching accessory
</button>
</div>
<!-- Show upgrade option -->
<div data-next-show="cart.hasItem(123) && !cart.hasItem(789)">
<button data-next-action="swap"
data-next-package-id="789"
data-next-remove-package-id="123">
Upgrade to Premium
</button>
</div>
<!-- Bulk discount tiers -->
<div data-next-show="cart.totalQuantity >= 3 && cart.totalQuantity < 5">
10% bulk discount applied
</div>
<div data-next-show="cart.totalQuantity >= 5 && cart.totalQuantity < 10">
15% bulk discount applied
</div>
<div data-next-show="cart.totalQuantity >= 10">
20% bulk discount applied - Maximum savings!
</div>

Use simple conditions when possible

<div data-next-show="cart.hasItems">

Combine related conditions

<div data-next-show="cart.total > 50 && cart.totalQuantity > 2">

Use built-in properties

<div data-next-show="cart.isEmpty">

Don’t nest conditions unnecessarily

<!-- Inefficient -->
<div data-next-show="cart.hasItems">
<div data-next-show="cart.total > 0">
<div data-next-show="cart.totalQuantity > 0">

Combine into single condition

<!-- Efficient -->
<div data-next-show="cart.hasItems && cart.total > 0">

With ?debugger=true, the SDK shows:

  • Current evaluated values
  • Condition results
  • Applied state classes
  • Re-evaluation frequency
<!-- Debug mode shows evaluation -->
<div data-next-show="cart.total > 100"
data-debug-condition="cart.total > 100"
data-debug-result="false"
data-debug-values="cart.total=75">
Free shipping
</div>

The SDK safely handles null/undefined values:

<!-- Safe even if package doesn't exist -->
<div data-next-show="package.999.price > 0">
<!-- Won't show or cause errors -->
</div>

Conditions are evaluated after data loads:

<!-- Won't flicker during load -->
<div data-next-show="campaign.isLoaded && cart.total > 0">
Ready to checkout
</div>

Conditions re-evaluate when data changes:

// Changing cart will update all conditions
await next.addItem({ packageId: 123 });
// All data-next-show/hide automatically update