Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Jan 06, 2016 @ 11:42
    Ismail Mayat
    0

    VIrtual page A to Z

    Just need a bit of advice on best way to approach this particular problem. I am looking to create an A to Z. I have a main index page that lists out the A to Z of letters. Each letter has url /stations/A etc. The page /stations/A does not exist nor does a page for each letter of the alphabet.

    So what am looking a doing is when the letter is clicked you end up on the stations page but as part of the url has the letter i want to get that letter then list only stuff for that letter. What is the best way of achieving this in v7? Implement ContentFinder?

    Regards

    Ismail

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Jan 06, 2016 @ 12:10
    Dave Woestenborghs
    0

    Hi Ismail,

    I would do this with a virtual node handler.

    Here is some more information about it :

    http://jamessouth.me/archive/fun-with-umbracovirtualnoderoutehandler/

    Dave

  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Jan 06, 2016 @ 14:08
    Ismail Mayat
    101

    Dave,

    Ok got this working in a different way, I created a ContentFinder:

    public class StationsContentFinder : ContentFinderByNiceUrl
    {
        public override bool TryFindContent(PublishedContentRequest request)
        {
            if (base.TryFindContent(request)) return true;
    
            var urlChunks = request.Uri.AbsolutePath.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
    
            if (IsSingleLetter(urlChunks))
            {
    
                string stationsXpath = "//Stations";
    
                var stationsNode =  request.RoutingContext.UmbracoContext.ContentCache.GetByXPath(stationsUrl).FirstOrDefault();
    
                if (stationsNode == null) { return false; }
    
                request.PublishedContent = stationsNode;
    
                //the stations hijack will take over and test for the letter and get the list of stations
    
                return true;
            }
            return false;
        }
    
        private static bool IsSingleLetter(List<string> urlChunks)
        {
            return urlChunks.Last().Length == 1 && Char.IsLetter(urlChunks.Last().ToCharArray()[0]);
        }
    }
    

    That works.

    Regards

    Ismail

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Jan 06, 2016 @ 14:12
    Dave Woestenborghs
    0

    That of course is also an option :-)

    Dave

  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Jan 06, 2016 @ 14:33
    Ismail Mayat
    0

    The only issue i have is that is multilingual site atm its only in english but potentially i could end up returning more than one station node I need to figure out how to get current region id and use that as filter.

    Regards

    Ismail

  • Ismail Mayat 4511 posts 10059 karma points MVP 2x admin c-trib
    Jan 06, 2016 @ 15:13
    Ismail Mayat
    0

    Ok so no i have

        const string StationsXPath = "//Stations[contains(@path,'{0}')]";
    
    var rootId = request.UmbracoDomain.RootContentId; // multilingual site we need root 
    
    string stationXPath = string.Format(StationsXPath, rootId);
    
    var stationsNode =  request.RoutingContext.UmbracoContext.ContentCache.GetByXPath(stationXPath).FirstOrDefault();
    

    Which works woohoo!

    Ismail

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies