How to create a page from within another page in panel

Hi everyone!

I’m currently building a blog with articles that have tags attached to them. I want to be able to link each tag to a separate page on the blog (/tag/tag-slug) where visitors can see the tag name, an optional description of the tag, and links to all the articles that have been tagged with it.

Currently, I’m going about this by creating the tags as separate pages in the panel and linking them to the articles via a tag field. Here’s what that looks like in my article.yml file:

tags:
                label: Tags
                type: tags
                options: query
                query: site.find("tags").children

The problem with doing it this way is that I have to create and publish every single tag as a page before I can use them as tags within my articles.

Is there a way I can create these tag pages and publish them directly from my article page on the panel? Or better still, is there an easier way to achieve this tagging system without manually creating a page for each tag?

Yes, you can achieve this via a route, see the docs about routing:

So your route pattern would be tag/(:any), then you can filter your article collection by this tag

How can I add the descriptions to each tag using this method?

You would have to define your tags somewhere, for example in the blog page in a structure field with tag name and description.

Ah, seen. Just to make sure I understand what you mean: from your suggestion, I’d pre-create the tags using a structure on the blog page, then I’d add them to the articles and then fetch articles for specific tags using a custom route?

Exactly.

The downside of this approach is that you have to create the tags first. But you need a way to attach descriptions for each tag, otherwise you wouldn’t need this step.

Alright. This isn’t ideal, but it’s better than what I currently have.

Thank you!

As I wrote, if you skip the tag description (why is this necessary?), then you wouldn’t need the structure field and could just create a route for filtering by the existing tags.