Constructing correct urls for Dynamic Pages with nested dynamic pages (.net c#)
I have a dynamic page item setup under another dynamic page item:
- Page-1
---Category
---Article
This creates a page path like /page-1/category/article.
The problem I am having is when loading a dynamic page item, it is unaware it is associated with its parent, and no way to get the actual full url to that article item.
Is there a way in Agility's .NET API to figure out the full page path for the "Article"? Perhaps looking it up within the applications Site Map Node Tree?
Comments
When you have multiple routes for a single post, it can get complicated no doubt!
Check out this github repo for an example of how to this.
The key line here is:
Does that help?
Are you rendering the category page and trying to build URLs for all the articles on that page, or are you on the article page, trying to render URLs for its parent category?
I am trying to render URLs for the parent page paths of a set of dynamic pages.
In the past I've done this through convention, as well as creating a settings panel where the "root page" is set, and I get the path of a particular category to construct a url like /{root-page-in-configuration}/{category}/{article} while on an "article" item.
But what if you have a singular Content Item that generates two routes for instance?
Now you have to pick apart the current page's url to figure out where the user is.
I'm curious on how you have handled this in other MVC projects?

Considering you define a dropdown of "build pages from" in Agility, it is too bad that this isn't captured in the API and returned with the Dynamic Page item:
With these dynamic pages, I could always try and get the "parent" of the current page to figure out the correct path, not sure what the most efficient way to do that is in Agility, and with Dynamic Pages specifically.
I'm looking for a reusable solution when it comes to these pags.
Any thoughts?
Awesome James that definitely helps with getting the correct category item by site map node.
Thank you very much!
Do you think my idea about the Agility API returning a "Build Pages From" property on dynamic pages makes sense?
Like in an instance where you have to list out all paths to each blog post, and you want to be able to create it in a way where you don't need to know the structure of the dynamic pages (which could be easily changed by a content editor).
In any regard what you have provided is very helpful thank you :)
Giovanni Mattucci - there is a way actually to build the dynamic URL path for a content item. But, you do need to know the path to the dynamic page node.
For example, here is a custom property added in C# (to a partial class that extends the content item properties):
And you would call it like this:
I wanted to share a way I have been getting the actual URL for dynamic page items.
If you can get the contentId of the dynamic page in question, in your .net core sdk I have been doing the following where I find the item referencing the root sitemap item of the site:
Hopefully this could be useful to others.
Let me know also if this way of doing it has any problems from a performance perspective.
Please sign in to leave a comment.