Conditions

What are conditions?

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:

ValueWhere it comes fromExample
A stateA 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 recordA field of the item a list repeats, or of the record a details page shows.stock = 0 on a product card.
A URL parameterA 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 visitorUser 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 storeE-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 languageCurrent Language (short, such as en, or name), under global.short = de shows a block only in German.
A data source or a global stateA 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 onThe screen sizeA value: state, setting, data, visitor, cart, address
On the published siteIn the page, not displayedNot in the page while the rule is false
Changes while the visitor uses the pageNoYes
WhereRight panel → Visual → VisibilityRight 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.
Share

Related Articles

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.

How to use conditions in components and variants

In TeleportHQ, a condition inside a component can read one of the component's settings (props): click Bind in the Conditional Rendering section and choose Create Conditional Prop, and every copy of the component then turns that part on or off, or picks a look, under Component Properties → Conditional; one card component gets several looks without being duplicated.

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.