Created
September 7, 2012 11:25
-
-
Save willprice76/3665333 to your computer and use it in GitHub Desktop.
Pageless Tridion Content Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TridionModel | |
{ | |
public XDocument GetContent(string contentType, string url) | |
{ | |
int publicationId = Int32.Parse(ConfigurationManager.AppSettings["tridion:publicationid"]); | |
var cpf = new ComponentPresentationFactory(publicationId); | |
int itemId = ViewHelper.GetIdFromUrl(url); | |
if (itemId > 0) | |
{ | |
var cp = cpf.GetComponentPresentationWithOutputFormat(itemId, "Xml Document"); | |
if (cp != null) | |
{ | |
return XDocument.Parse(cp.Content); | |
} | |
} | |
return null; | |
} | |
} | |
public class ViewHelper | |
{ | |
public static int GetIdFromUrl(string url) | |
{ | |
Match match = Regex.Match(url, @"(?<title>[^/]*?)_(?<id>\d+?)\."); | |
if (match != null) | |
{ | |
return Int32.Parse(match.Groups["id"].Value); | |
} | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment