Conditions

How to show or hide elements based on a condition

How to show or hide elements based on a condition

In TeleportHQ, conditional rendering shows an element only when a condition is true, for example a "Sold out" badge when stock equals 0, or a menu panel only while a state isMenuOpen is true. Select the element, turn on the Conditional Rendering switch near the top of the right panel, under Workflows, and build the condition from a value, an operator and a comparison value. Conditions work in every TeleportHQ project, website or web app, and need no extra setting.

Before you start

  • Nothing to turn on. Conditional rendering is on in every TeleportHQ project. It isn't an advanced feature any more, and using it doesn't turn a website into a web app.
  • You need a value to test: a field of a list item or of a details page, a state, a component setting (prop), or a built-in value such as User is logged in. To make a value that a click can change, see How to store and use values with States.
  • Role. You need a role that can edit the project, for example Designer.
  • New to conditions? What are conditions? explains what a condition can read and what happens on your published site.

Steps

1. Turn on the Conditional Rendering switch

  1. On the canvas, select the element to show or hide, for example a "Sold out" badge inside a product card.
  2. In the right panel, make sure the Visual tab is open.
  3. Near the top of the right panel, under Workflows, find the Conditional Rendering section.
  4. Turn on the Conditional Rendering switch at the right of the section's title. The section shows a Bind button, an Operand list and a value box.

    The Conditional Rendering section near the top of the TeleportHQ right panel, with its switch highlighted

2. Build the condition

  1. Click Bind. A small menu opens.
  2. Click Dynamic Properties Assignment Panel. The Select Dynamic Property panel opens.
  3. Choose the value to test, for example the list item's stock field, and click Bind property.
  4. In the Operand list, choose how to compare, for example =.
  5. In the value box, type the comparison value, for example 0.

The badge now only shows on cards whose stock is 0.

The TeleportHQ Conditional Rendering section switched on, with the Bind button and the Operand list

To compare with another value instead of typed text, click the plug icon next to the value box and choose Dynamic Properties Assignment Panel. Insert Code Expression in the same menu lets you type a formula instead.

Operators you can use

The Operand list in a TeleportHQ condition depends on the type of value you test:

  • Text, numbers and true/false: =, !=, >, >=, <, <=.
  • Lists: contains, does_not_contain, is_empty, is_not_empty, length_equals, length_greater_than, length_less_than. With contains, a Match by field (optional): box lets you compare one field of each item, for example id.
  • Objects: has_key, does_not_have_key, is_empty, is_not_empty.

is_empty and is_not_empty need no comparison value.

Combine several conditions

To require more than one thing in TeleportHQ, for example "logged in and the cart is not empty", first bind the first value. Then:

  • Click + condition to add another condition. Between two conditions, choose and (all must be true) or or (one is enough).
  • Click + group to add a group of conditions. At the top of the group, choose all of or any of, and add conditions inside it with its own + condition.

To remove a condition or a group, click the × at its right.

See hidden elements while designing

An element whose condition is false doesn't show on the canvas. TeleportHQ gives you three ways to see it:

  • Change the value the canvas uses. When the selected element is hidden, the section says "Element not visible in the canvas! The current value of <value> is <v>." Click the Set … to … button below it, and the canvas shows the element. This only changes the value the editor uses for its preview.
  • Show every hidden element. At the bottom center of the canvas, click See all conditionally rendered nodes. Every element with a condition shows until you click Showing all conditional nodes again. The button only appears on pages that have conditions.
  • Use the canvas switch. When a state switches a section between several views (tabs, or a price toggle for monthly and yearly), a small switch appears on the canvas while you point at that section or select something in it. It lists every view; click one to see it. Visitors still start on the view your state starts with.
The See all conditionally rendered nodes button at the bottom center of the TeleportHQ canvas

Common examples

  • Open and close something on a click: create a state isOpen (true or false), show the panel when isOpen = true, and give the button a Change State event that toggles isOpen. See How to show or hide elements by state.
  • Tabs: create a state activeTab, show each tab's content when activeTab = 1, 2 or 3, and make each tab button change the state. The Tabs element in Elements builds this for you.
  • Show a Log out button only to signed-in visitors: test User is logged in = true. Signing in needs user accounts, which make a site a web app. See How to show or hide elements for signed-in visitors.
  • Hide an empty field: test the field with is_not_empty when it's a list, or with != and an empty value when it's text. For a placeholder text instead, see How to show a fallback when data is missing.
  • Ask the AI Assistant: you can also ask it, for example "Show the sale banner only when the cart is empty". It can add conditions on a website without making it a web app.

More worked examples, from an accordion to a "no results" message, are in Condition recipes.

Check that it worked

Change the value you test, for example switch the previewed item or the state's value, and watch the element appear and disappear. Then click Preview in the bottom toolbar and try it as a visitor would, for example by clicking the button that changes the state.

Troubleshooting

I can't find the Conditional Rendering section You selected a component's main (outermost) element, which can't have a condition. Select an element inside it, or select the copy of the component on the page. If the Advanced or Events tab is open in the right panel, click Visual.

"Right side operator is an expression. The canvas will always treat this case as true and show it." The comparison value is a formula, which the editor can't work out. The canvas shows the element; check the real result in Preview or on your published site.

My condition disappeared Turning the Conditional Rendering switch off deletes the condition. Click Undo above the canvas, or set it up again.

The element shows in the editor but not on my live site (or the other way round) The canvas uses the value set in the editor, for example a state's Internal value or the item picked on a details page. Visitors start with the state's Default value. See Why does my data look different in the editor and on my live site?

Good to know

  • Elements hidden by a condition are still part of the page. Visitors don't see them while the condition is false.
  • See all conditionally rendered nodes and the Set … to … button only change what the editor shows, never your site.
  • Downloaded code: the Next.js download runs every condition. The HTML download runs conditions on states, such as a menu that opens on a click. Conditions on a component's props are worked out for each copy when the site is built, so every copy keeps the version you picked for it; other conditions are worked out once, from the values the page starts with. See How to download your site as code.
  • To hide an element on every page load, for example on mobile only, use visibility settings instead. See How to hide an element.
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 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.