Join the Webstudio community

Updated 2 months ago

Variable for all Pages?

At a glance

The community members are discussing a way to automatically generate a site menu by retrieving a list of all pages in the project. The goal is to have a variable or mechanism that provides the page titles and URLs, so that the menu can be populated without manually adding each entry. Some suggestions include using a system variable to expose page data, extending the existing sitemap resource, or creating a separate resource with a nested tree structure to handle nested navigation. The community members agree this would be a helpful feature, and plan to create an issue to further discuss the implementation.

Useful resources
Hi,

Was building a site menu and looking to fill out the entries in that automatically. Is there a way to get a variable, or through some mechanism, for all the pages that are in the project? And then I can add the title to the link text and the URL for clicking it. Would also be ideal if I could filter on those - so I can add a variable on some pages to hide them from the menu, if they're a work in progress etc.

Thanks!
2
X
b
p
26 comments
I can't quite understand what you want to do, do you have a visual example?

Is it a component system that you are trying to make?
Yeah I can try and mock up a screenthos
Some kind of slot where a list of all pages shows up that then gets rendered as the menu automagically
E.g. a variable like Site.AllPages => ["Contact": {..., "url": "/contact"}, "About": {..., "url": "/about"}]
So if I add a new page and it appears in the menu without having to add a link by hand
I see what I thought was an upload icon is actually a folder as first thought, that would be even easier - basic way to iterate over the pages in that folder
I agree, this would be a helpful feature
I think we discussed a while ago internally that we could expose pages data under system variable so you can use a collection component to iterate over it and render those lists

@TrySound do you remember if there was consensus on it?
We didn't have collection and system variable back then and decided to go with http requests for simplicity
Wdyt about providing minimal pages data over system?
I would better go with system resource we already use for sitemap
so just extending sitemap resource with added data about each page?
or even complete page data
Yes, or separate one
Might need a separate one because the question is how to render a nested pages with nasted navigation etc
The structure might need to be in the tree form so that one can nest collections
Will create an issue
Nested but not traversed?
and also user doesn't have to build the path manually, we could prepare the path for each page that's complete
Collections do not traverse nested trees so amount of nested collections is managed by user
Yes, user would have to create nested collections to render children
Add a reply
Sign up and join the conversation on Discord