Conditions

How to show or hide elements by URL parameter

How to show or hide elements by URL parameter

In TeleportHQ, a condition can read a value from the page's address, the part after ?, such as category=cakes in /products?category=cakes. First declare the parameter on the page: click Page settings above the canvas and add it under Page Params, with a Key name and a Default value. The Select Dynamic Property panel then lists it under URL Param, and a rule such as category = cakes shows an element only to visitors who arrive with that address. This gives you campaign variants (?offer=spring), category views (?category=cakes) and deep links to one part of a page (?tab=reviews).

Before you start

  • A web app. Page Params show in Page settings of a web app. On a presentation website the section isn't there. See What's the difference between a website and a web app?
  • A regular page. Details pages, which show one record each, have no Page Params.
  • Role. You need a role that can edit the project, for example Designer.

Steps

The example shows a "Spring offer" banner only to visitors who open the page with ?offer=spring.

1. Declare the parameter on the page

  1. Open the page on the canvas. Above the top right of the canvas, click Page settings.
  2. Open the SEO tab and scroll to Page Params. Its description reads "Declare the URL search parameters this page accepts (e.g. ?category=food). Filters on this page and workflows that navigate here can then bind to these keys."
  3. In Key name, type offer. A key starts with a letter and holds only letters, numbers and underscores.
  4. In Default value, type what the page uses when the address has no offer, or leave it empty.
  5. Press Enter, or click outside the fields. The row is saved, and the line Declared keys: lists offer.

To remove a parameter, click Remove (the cross) at the end of its row.

2. Put the rule on the element

  1. On the canvas, select the banner.
  2. In the right panel → Visual tab, turn on the Conditional Rendering switch.
  3. Click Bind, then Dynamic Properties Assignment Panel.
  4. In the Select Dynamic Property panel, open URL Param, click offer, then click Bind property. URL Param sits right after state and props in the list.
  5. Keep = in the Operand list and type spring in the value box.

3. Publish and share the address

Publish the site. Share https://yourdomain.com/offers?offer=spring in the campaign. A visitor who opens it sees the banner; a visitor who opens /offers doesn't.

Three ways to use it

  • Campaign variants: offer with rules = spring on one banner and = newsletter on another. One page, one address per campaign.
  • Category views: category with = cakes on a cakes intro and = bread on a bread intro. The list on the same page can filter by the same parameter. See How to filter a list.
  • Deep links: tab with = reviews on the reviews block, so a link from an email opens the page on the reviews. For a tab a visitor can also click, pair the parameter with a state: see Good to know.

Check that it worked

On the canvas, the parameter has its Default value, so an element whose rule needs another value is gone from the canvas. Click See all conditionally rendered nodes at the bottom center of the canvas to see it. On your published site, open the page with the parameter in the address, then without it.

Troubleshooting

URL Param isn't in the panel The page declares no parameter yet. Add one under Page Params in Page settings. For an element inside a component, URL Param is listed only while that component is used on exactly one page that declares parameters.

"Key must start with a letter and contain only letters, numbers, or underscores." Change the key, for example offer_code instead of offer-code.

"A parameter with this key already exists." The page already has that key. Use the row that exists.

The element never shows on the canvas The canvas uses the Default value. Set the Default value to the value the rule needs while you design, then change it back, or use See all conditionally rendered nodes.

The element shows on my site even without the parameter The Default value equals the value the rule tests. Clear it, or test for another value.

Good to know

  • The parameter is read on every visit. The published page reads the address when it loads, with the Default value as fallback when the parameter is missing or empty.
  • A state can start from the parameter. In Page settings → State, a state's starting value can be read from a URL Param. The published page then keeps the two in step: a button that changes the state updates the address, and the browser's back button updates the state.
  • Several parameters. A page can declare any number of keys, and a rule can combine them with + condition, for example offer = spring and lang = de.
  • Downloaded code. The Next.js download reads the parameters. 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 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.