What are conditions?
A condition in TeleportHQ is a rule attached to one element. A bakery's store, for example, shows a "Sold out" badge only while a product's stock equals 0, and a menu panel only while a state named isMenuOpen is true. You set the rule in the Conditional Rendering section of the right panel. While the rule is false, the element is left out of the page: it is not in the page's code, not merely hidden from view. Conditions work in every TeleportHQ project, website or web app, with nothing to turn on first.
Where you set a condition
Select the element on the canvas and open the Visual tab of the right panel. The Conditional Rendering section sits near the top, under Workflows. Its switch turns the rule on. The section then shows a Bind button, an Operand list and a value box: the value to test, how to compare it, and what to compare it with. For a "Sold out" badge that reads stock = 0. The click-by-click version is in How to show or hide elements based on a condition.
A condition belongs to the element you selected and to everything inside it. A rule on a section hides the whole section, its texts and buttons included. One element holds one rule, and that rule can have several parts joined with and or or, or grouped with all of and any of.
What a condition can read
Bind opens a small menu. Dynamic Properties Assignment Panel in it opens the Select Dynamic Property panel, the list of values your project has. What it lists depends on the element and on the project:
| Value | Where it comes from | Example |
|---|---|---|
| A state | A value the page or component remembers, created in Page settings → State. | activeTab = 2 shows the second tab. See How to show or hide elements by state. |
| A component setting (prop) | A setting each copy of a component fills in on its own, listed under props. | showIcon = true shows an arrow on one copy of a button. See How to use conditions in components and variants. |
| A list item or a page record | A field of the item a list repeats, or of the record a details page shows. | stock = 0 on a product card. |
| A URL parameter | A value from the page address, listed under URL Param once the page declares it in Page Params. | category = cakes on /products?category=cakes. See How to show or hide elements by URL parameter. |
| The visitor | User is logged in (true or false) and Current User (name, email, role and more), under global, when your site has sign-up and login. | User is logged in = true shows a Sign out button. See How to show or hide elements for signed-in visitors. |
| The cart and the store | E-commerce → Cart (itemCount, shippingIsFree, total and more) and the store's Settings, under global, when your project has a store. | itemCount = 0 shows "Your cart is empty". See How to show or hide elements by cart and store values. |
| The language | Current Language (short, such as en, or name), under global. | short = de shows a block only in German. |
| A data source or a global state | A value read from a connected data source, or a global state of a web app. | A notice shown while a sheet's open cell reads yes. |
The value box changes with what you picked. For a true/false value it offers true and false. For Current Language it lists your site's languages. For a number it takes a number.
What happens on the published site
On the published site, TeleportHQ writes each condition into the page's code as "rule and element". While the rule is false, the element is not created at all. A visitor who opens the page's source, or a search engine that reads it, finds nothing of it. When the rule turns true, for example when the visitor clicks a button that changes a state, the element is created at that moment.
The canvas in the editor works the same way, with the values the editor holds: a state's Internal value, the record picked on a details page, the user picked with the padlock button, the cart from the cart simulator. When the rule is false, the element is gone from the canvas too, and the Conditional Rendering section says "Element not visible in the canvas! The current value of <value> is <v>." A Set … to … button under it changes the editor's value so you can keep designing; it never changes your site. The pill See all conditionally rendered nodes at the bottom center of the canvas shows every hidden element at once, and reads Showing all conditional nodes while it does.
Conditions and Hide are different
The eye toggle in the Visibility section hides an element on the canvas and on the published site, at the screen size you are editing and all smaller ones. The element stays in the page's code with a "do not display" style. Use it for an element that should never show at that size, for example a wide table on phones. See How to hide an element.
A condition is a rule that can change while the visitor uses the page. Use it when the answer depends on something: a click, a sign-in, a value in your data, the address the visitor arrived at. The element is left out of the page while the rule is false, and comes back when the rule turns true.
| Hide (Visibility) | Condition (Conditional Rendering) | |
|---|---|---|
| Depends on | The screen size | A value: state, setting, data, visitor, cart, address |
| On the published site | In the page, not displayed | Not in the page while the rule is false |
| Changes while the visitor uses the page | No | Yes |
| Where | Right panel → Visual → Visibility | Right panel → Visual → Conditional Rendering |
Good to know
- Turning the switch off deletes the rule. Click Undo above the canvas to get it back.
- A component's outermost element cannot hold a condition. Put the rule on an element inside it, or on the copy of the component placed on the page.
- Downloaded code. The Next.js download runs every condition. The HTML download runs conditions on states; conditions on a component's settings are worked out once for each copy when the site is built. See How to download your site as code.
- Worked examples, from an accordion to a "no results" message, are in Condition recipes.