How do I use route patterns in my project?
Learn how to use route patterns in Blutui to dynamically generate pages from collections, such as individual team member profiles.
Introduction
Route patterns allow you to create dynamic URLs that render content based on your collections.
They’re perfect for building templates like individual team member, product, or blog post pages — without needing to manually create each page.
In this guide, we’ll walk through how to use a route pattern to dynamically display a team member’s profile page based on their name.
Create a layout for your route pattern
Before you create a route pattern, you’ll need a layout that will render your dynamic content.
In this example, we’ll build a route pattern for team members.
Start by creating a layout named:
team-member.htmlThis layout will be used to render each team member’s details when their unique URL is visited.
Create a route pattern in your dashboard
- Open your project in the Blutui dashboard.
- Navigate to Settings → Route Patterns.
- Click Create route pattern.
In this example, we’ll set the route pattern to:
/team/{name}Now configure the pattern parts:
- Click the String button and name it
team. - Click the Slug button and name it
name. - Select your team-member layout as the layout to render.
- Click Create route pattern.
This pattern tells Blutui to render the team-member.html layout whenever a URL matches /team/{name} — for example, /team/darth-vader.
Add logic to your layout
Next, open your team-member.html layout and add the following code:
{% set members = cms.collection('team') %}
{% set member = members | filter(entry => (entry.name | slug) == route.data.name) | first %}Here’s what this code does:
- Fetches the team collection.
- Filters the collection by comparing the slugified name of each team member with the
{name}value from the route pattern. - Sets the matching entry as
member.
This means that when you visit a URL like /team/darth-vader, Blutui will:
- Take
darth-vaderfrom the URL. - Match it against the slugged name field in your team collection.
- Render the
team-memberlayout using that specific entry’s data.
Display the collection data
Now that the matching team member is set, you can render their details anywhere in the layout:
<div class="team-member">
<img src="{{ member.avatar }}" alt="{{ member.name }}">
<h1>{{ member.name }}</h1>
<p>{{ member.bio }}</p>
</div>This will dynamically populate the page with each team member’s unique information.
Why use route patterns?
Route patterns are incredibly powerful for creating data-driven pages without manually adding routes or pages. They’re ideal for:
- Products (
/products/{id}) - Locations (
/locations/{city}) - Team members (
/team/{name})
With route patterns, your content scales automatically as you add new entries to your collections.
Next steps
Now that you’ve set up a route pattern, try expanding it with related collections, or use nested route patterns for more advanced structures (e.g., /{region}/{slug}).
Last updated on