Conditions

How to use conditions in components and variants

How to use conditions in components and variants

In TeleportHQ, a condition inside a component can read one of the component's own settings (props), so one component gets several looks. Open the component, select the part to show or hide, turn on Conditional Rendering, click Bind and choose Create Conditional Prop: TeleportHQ makes the setting and binds the rule to it. Every copy of the component on your pages then turns the part on or off under Component Properties → Conditional, with a False | True switch. A product card can show a "Sale" ribbon on some copies, a price on others, and a wide layout on a third, all from one component.

Before you start

  • A component. Props and conditional props exist inside components, not on pages. See How to create a component.
  • Know the two kinds of rule. A condition on an element shows or hides a part. A rendering condition on a class turns a look on, such as a full-width button. See How to turn a part of a component on or off.
  • Role. You need the Owner, Admin or Designer role.

Steps

The example is a ProductCard component with a "Sale" ribbon that only some copies show.

1. Make the setting and the rule in one go

  1. In the left sidebar, open Pages, Components & Tree View, and in the Components folder click ProductCard.
  2. On the component canvas, select the ribbon. Don't select the card's outermost element: it can't hold a condition.
  3. In the right panel → Visual tab, turn on the Conditional Rendering switch.
  4. Click Bind. Inside a component, the menu offers Create Conditional Prop and Dynamic Properties Assignment Panel.
  5. Click Create Conditional Prop. In the Create Conditional Prop window, type the name onSale. Type is boolean and Default is False: leave both. Click Create.
  6. Keep = in the Operand list, click the value box (Pick a value) and pick true.

The ribbon disappears from the component canvas, and the section says "Element not visible in the canvas! The current value of onSale is false." Click Set onSale to true to see the ribbon while you design it. That changes the prop's Internal value, which the editor uses and your copies ignore.

2. Turn it on, copy by copy

  1. Go back to a page with copies of ProductCard and click one.
  2. In the right panel, under Component Properties, open the Conditional group. onSale has a False | True switch.
  3. Click True on the copies that are on sale.

3. Use a setting you already have

If the component already has a setting, such as a text prop layout, bind the rule to it instead: click Bind → Dynamic Properties Assignment Panel, open props, click layout, then Bind property. Type the value in the value box, for example wide. A copy then picks wide from a list under Component Properties: the list offers the values your conditions compare against, so a second rule with = compact adds compact to it.

One card, several looks

Combine a few rules on ProductCard and each copy picks its look:

Part of the cardRuleCopy setting
"Sale" ribbononSale = truethe onSale switch set to True
PriceshowPrice = truethe showPrice switch set to True
Image on toplayout = verticallayout set to vertical
Image on the leftlayout = horizontallayout set to horizontal
Stock linethe list item's stock > 0none: it reads the product

A look that changes styles rather than parts, such as a wider card, is a class with a rendering condition: on the class row in the Classes section, click Add rendering condition and bind it the same way. See How to build a button with four looks.

Check that it worked

  • On the page, a copy with onSale on shows the ribbon; a copy with it off doesn't.
  • Click Preview in the bottom toolbar: the same cards show.

Troubleshooting

Create Conditional Prop isn't in the Bind menu You're on a page, not inside the component. Open the component from the Components folder of Pages, Components & Tree View, then select the part again.

The setting is listed under Unassigned, not Conditional Its rule has no value yet. Open the component, select the part, and pick a value in the value box.

The ribbon shows on every copy The ribbon's Conditional Rendering switch is off, or its rule reads another value. Select the ribbon inside the component and check the section.

Set onSale to true did nothing on my copies It isn't meant to. The button changes only the editor's Internal value for the component canvas. Copies keep their own switch.

Good to know

  • A copy can have a rule too. Select the copy on the page and turn on Conditional Rendering there, to show the whole card only when, for example, the visitor is signed in.
  • A rule can read the list the card is in. When the card repeats in a list, its props can be bound to the item's fields, so onSale follows the product's sale field instead of a switch. See How to show a list of items.
  • Downloaded code. Conditions on a component's settings are worked out for each copy when the HTML download is built, so every copy keeps the version you picked for it. The Next.js download runs them. See How to download your site as code.
Share

Related Articles

What are conditions?

In TeleportHQ, a condition is a rule on one element, such as "show this badge while stock equals 0" or "show this menu while isMenuOpen is true"; you set it in the Conditional Rendering section of the right panel, it can read a state, a component setting, a list item, the signed-in visitor, the cart or a URL parameter, and on the published site the element is left out of the page while the rule is false.

How to show or hide elements based on a condition

In TeleportHQ, you show an element only when a condition is true, such as "stock equals 0" or "the menu is open", by selecting it, turning on the Conditional Rendering switch near the top of the right panel and building the condition from a value, an operator and a comparison value; it works in every project, website or web app.

How to show or hide elements by state

In TeleportHQ, create a state in Page settings → State (for example isMenuOpen, true or false), give the element a Conditional Rendering rule such as isMenuOpen = true, and change the state from a button's Events tab with Change State; it works on websites and web apps and needs no web app features.

How to show or hide elements for signed-in visitors

In TeleportHQ, a web app with sign-up and login offers two built-in values under global in the Select Dynamic Property panel, User is logged in (true or false) and Current User (name, email, role and more); a condition such as User is logged in = true shows a Sign out button, = false a Sign in link, and Current User → role = admin a button for one role only.

How to show or hide elements by URL parameter

In TeleportHQ, declare the parameter on the page under Page Params in Page settings (a Key name such as category and a Default value), then give the element a Conditional Rendering rule on the URL Param, such as category = cakes; a visitor who opens /products?category=cakes sees that element, and the page without the parameter uses the default.

How to show or hide elements by cart and store values

In a TeleportHQ store, the Select Dynamic Property panel lists the visitor's cart under global → E-commerce → Cart (itemCount, total, shippingIsFree, freeDeliveryRemaining and more) and the store's Settings; a rule such as shippingIsFree = false shows a "Spend more for free delivery" banner, itemCount = 0 an empty-cart message, and a product's stock field a "Only 3 left" label.

Condition recipes

Six ready-to-copy TeleportHQ conditions, each with the state or value to create and the rule to set: an accordion and tabs built from a state (or the Accordion and Tabs elements that do it for you), an image slider with a slide state, a "no results" message with is_empty, a language-specific block on Current Language → short, and a fallback for a missing field.