Home App Docs Blog Github

How to pull a custom URL slug / permalink from a model?

Hey team, how can I have a Builder page pull its content (including a custom URL slug / permalink) dynamically from a separate model?

Context: I built a page that pulls its content from a separate model (called Story) in builder. Each time a new Story is published, a new version of the page becomes available to view the Story’s content. Currently, the page works by including the Story - Id in the URL path. However, I am trying to figure out a solution that allows us to customize the URL.

Here’s the page in builder: https://builder.io/content/7358745c5aa6494da0bb79a7395c6aea

Here’s the Story model in builder: https://builder.io/models/74d0f168c1b641d19941ac54e5d259ca

Here’s an example of a public page producing a Story: https://thenewpaper.co/story/f67258133c154157b05d47cae83acf77

In this example above, the aim is to make the URL something like: “https://thenewpaper.co/story/inda-coronavirus-cases

Hi John! Thanks for reaching out. Here are two docs that will be helpful: https://www.builder.io/c/docs/guides/advanced-data and you can use our content API: https://www.builder.io/c/docs/query-api.

For your use case, you can query by slug/handle like this var url = https://cdn.builder.io/api/v2/content/story?query.data.slug=${state.location.path[1]}&apiKey=${YOUR_KEY}

I hope this was helpful! If you have any questions, feel free to reach back out!

Hi Kara, thanks for the response. This makes sense and should solve the issue!

Great, thanks for your question! :grinning: