Nested Wildcards to Handle Virtual Items in Siteco

2019-07-15 13:25发布

问题:

TLDR; What is the best or recommended way to work with complex virtual items at multiple levels?

I'm working on something currently that instead of using query string variables to filter properties, I would just like to extend the URL and allow those URLs to filter.
Events:
~/events/2012/april or
~/events/lunches or
~/events/6CB27D08-358E-49AA-8107-16A50E963C70

I currently have a wildcard setup to handle the last case or the year but ran into the snag of a wildcard only handling one level so I'm unable to handle /events/{0}/{1} with just one wildcard. Further more, I believe that the common friendly url would end up being /events/2012/april/<external_id>_<event_name>

Using wildcards, I would need to put them three layers deep with three different layouts to handle each case from what I know currently

Events/
        *
          *
            *

Is there a better way or a more recommended way to deal with complex virtual items at multiple levels?

回答1:

You are on the correct path here and you are correct in that you would need a wildcard item for each segment of the URL. However, just because a wildcard exists doesn't mean you need to use it. In other words, the /events/*/* item would handle the /events/2012/april URL.

You may want to look at this blog post http://www.sitecore.net/Community/Technical-Blogs/Getting-to-Know-Sitecore/Posts/2011/09/Wildcards-and-Data-Driven-URLs.aspx that leads to the Wildcard Module



回答2:

Is there a specific reason for using the wildcard items? I think you are better off with URL rewriting if you're are going more than 1 level deep with wildcards.

So make only the /events item and rewrite /events/{0}/{1} to /events?year={0}&month={1}