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?
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]);
}
}
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.
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();
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
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
Dave,
Ok got this working in a different way, I created a ContentFinder:
That works.
Regards
Ismail
That of course is also an option :-)
Dave
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
Ok so no i have
Which works woohoo!
Ismail
is working on a reply...