Conditions

Condition recipes

Condition recipes

These are the TeleportHQ conditions people ask for most, each with the value to create and the rule to set in the Conditional Rendering section of the right panel. Each one works on a website as well as a web app, and none needs the AI. Where TeleportHQ has a ready-made element that does the same, the recipe names it first: Accordion, Tabs and Slider are in Elements → Primitives → Interactive, and build their own show-and-hide.

The steps for creating a state and binding a rule are in How to show or hide elements by state. The operators (=, !=, >, is_empty and the rest) are listed in How to show or hide elements based on a condition.

An accordion

Ready-made: the Accordion element has an Accordion Trigger and an Accordion Content, a Default state (Open or Closed) and a Group Name so one answer at a time stays open. See How to create an accordion.

With a condition, for a layout the element doesn't give you:

  1. In Page settings → State, create openQuestion, type number, default 0.
  2. Select the first answer. Rule: openQuestion = 1. The second answer: openQuestion = 2, and so on.
  3. On each question's heading, add a Change State event: Modifies openQuestion, To its number. A heading that sets it to 0 closes everything.

Tabs

Ready-made: the Tabs element shows one panel per tab, with Current tab and Direction in its Tabs settings, and can take its tabs from data (Tabs source).

With a condition:

  1. Create activeTab, type number, default 1.
  2. Rule on the first panel: activeTab = 1; on the second: activeTab = 2.
  3. Each tab button gets a Change State event that sets activeTab to its number. To mark the active button, give it a class with a rendering condition on the same rule. See How to use conditions in components and variants.

A monthly/yearly price toggle is the same recipe with a text state billing, default monthly, and rules billing = monthly on one price list and = yearly on the other.

An image slider

Ready-made: the Slider element has slides, arrows, dots, autoplay and seven layouts. See How to create an image slider.

With a condition, for a "before and after" or a three-image showcase:

  1. Create slide, type number, default 1.
  2. Rule on the first image: slide = 1; on the second: slide = 2; on the third: slide = 3.
  3. Three small buttons set slide to 1, 2 and 3. The Next button needs one rule per position: a Next with slide = 1 that sets 2, another with slide = 2 that sets 3.

A "no results" message

For items held in a state filled from your data (see Fill a state from your data):

  1. Select the "No results" text.
  2. Rule: the state, for example products, with the operator is_empty. No value is needed.
  3. Give the list the opposite rule, products is_not_empty, so the two never show together.

For a CMS List or an Array Mapper bound to a data source, the list has its own empty state. See How to design loading, empty and error states.

A block for one language

On a multilingual site, a block that only German readers should see, for example a note on German delivery:

  1. Select the block.
  2. Click Bind → Dynamic Properties Assignment Panel, open global → Current Language, click short, then Bind property.
  3. Keep =. The value list offers your site's language codes: pick de.

For a rule on the language's name, pick name instead of short: the list then offers the names. A language switcher that shows a flag per language uses the same idea on each item of the switcher's list. See How to add a language switcher.

A field that is sometimes empty

Two ways, depending on what the reader should see:

  • Hide the element when the field is empty: on the element, rule description != with an empty value box for a text, or tags is_not_empty for a list.
  • Show a placeholder instead: type a fallback in the box under the binding, such as "No description yet". See How to show a fallback when data is missing.

Good to know

  • See the hidden version while designing with the Set … to … button in the Conditional Rendering section, or with See all conditionally rendered nodes at the bottom center of the canvas.
  • The canvas switch. When a state switches one section between views, point at the section: a small switch on the canvas lists the views.
  • Downloaded code. The HTML download runs the state recipes above; the language and data recipes need the Next.js download. 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.

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.