Skip to content

Instantly share code, notes, and snippets.

@willprice76
Created September 7, 2012 11:25
Show Gist options
  • Save willprice76/3665333 to your computer and use it in GitHub Desktop.
Save willprice76/3665333 to your computer and use it in GitHub Desktop.
Pageless Tridion Content Model
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