Join the Webstudio community

Updated 6 months ago

Dynamically Generated Top-level Pages in CMS with a Static Home Page

At a glance
I'm interested in having top-level pages dynamically generated by CMS. The Home page doesn't have a dynamic path attribute, though. Is there a workaround for this?
O
p
43 comments
Have you tried /:name ?
otherwise what do you mean by making home page dynamic, if you don't add some path to the root, how can it be dynamic?
I'd like to have a single page template for top-level pages, including the / (home) page. Webstudio's Home page can't be removed, and it also doesn't have a dynamic path attribute, so it can't be used as the template.
I may be misunderstanding something obvious
how do you imagine url to be?
how can it be dynamic?
what's dynamic about it?
its just a static url
I understand, thanks. So my goal is to have a single page template for all top-level pages, including / (Home). And I'd like the page content for each of these pages to be CMS generated
I had assumed I'd need to dynamically generate a slug for each of these pages, including an empty slug for /
that's just a bunch of resources on a single static url
its not separate pages, its one page
if you generate a slug it would be a different page like /x , /y etc
I am very confused about your requriements
Thanks for sticking with me. I'll try to be more clear.
Let's say I have three pages: / (home) , /about, and /faq. Currently, I can set up duplicate page templates in WS for each of them, and pull in resources for their content from a CMS. No problem there.
The question is then, what if I want a single WS page template for all three of these pages?
If I was excluding the / page, it would be no problem, because I could have a single template for /about and /faq that used /:slug.
But I'm not sure how to include the slugless home page among the dynamically generated pages
I still don't understand your use case, /home /about - 2 pages, one template, schema would be /{slug} where slug would be either home ore about
ah you want / and /about to reuse the same template
and since WS Home isn't removable, I'm kind of stuck with it, or a redirect from it to somewhere else
have you tried making slug optional, meaning if there is no slug, then you fetch what is meant for / (home)
I'll try that. What would that mean for the default WS Home page, though? Disable it? (via "Show")
try it, I am not sure what router will do right now when dynamic page is matching the root, which one it will take first
it might just work
if not we can consider opening an issue to make sure when this happens router takes the dynamic page over the home page
Ok, great. I'll try it and report back
I think for people coming from CMS's like WP and others, where they can expect a template to work with all pages including the root, it might be helpful to add something to the UX that helps clarify how its doneโ€” maybe add a dynamic path option to the Home page (with warnings/explanations) or something else
Maybe a disabled path input with a tooltip
That's sounds good.
I played around with this a bit.

In a published test site, the root page / is indeed routed to the common template (with dynamic path as /:slug? to make the slug optional) as I had hoped, and not to the default Home page. So it looks like no issue there ๐Ÿ™Œ
And I also followed your suggestion, adding logic in the variable expression to check for the existence of a slug and if true, get page content for the slug or if false, for the root page. That works perfectly.

Thanks!
Perfect, remains to make it obvious in the ui
Returning to this old thread to ask:

I'd like to have all pages, including / be using a dynamic path. As you helped me work out earlier, with :slug?, the root url someurl.com is routed to the common template with the dynamic path, and not Webstudio's default "Home" page. So far so good.

But this prevents me from using any path with more than one /. i.e. I can only use someurl.com/foo, but not someurl.com/foo/bar.

And using :slug* doesn't let me use this common template with someurl.com (no slug).

Any ideas for this?
Add a reply
Sign up and join the conversation on Discord