Skip to content

Instantly share code, notes, and snippets.

@willprice76
willprice76 / ComponentLinks.cs
Created August 20, 2012 21:25
Tridion Extended Component Link Control Example
@willprice76
willprice76 / pageless-tridion-content-getviewtype.cs
Created September 7, 2012 11:08
Pageless Tridion Content GetViewType
public static string GetViewType(string url)
{
return url.Contains(".html") ? "Detail" : "List";
}
@willprice76
willprice76 / pageless-tridion-content-getview.cs
Created September 7, 2012 11:18
Pageless Tridion Content GetView
private string GetView(string contentType, string url)
{
return "News" + TridionModel.GetViewType(url);
}
@willprice76
willprice76 / pageless-tridion-content-example-dcp.xml
Created September 7, 2012 11:19
Pageless Tridion Content Example DCP XML
<item id="3482">
<heading>Company Results 2011</heading>
<body>
Last year we made a stack of <strong>ca$h</strong> so everyone was happy... right?
</body>
<metadata>
<url>company-results-2011</url>
<description>The financial results for 2011 as formally announced to the market</description>
</metadata>
</item>
@willprice76
willprice76 / pageless-tridion-content-newsdetail.aspx
Created September 7, 2012 11:21
Pageless Tridion Content News Detail View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<XDocument>" %>
<html>
<head>
<title><%=Model.Root.Element("heading").Value %></title>
<meta name="description" content="<%=Model.Root.Element("metadata").Element("description") %>" />
</head>
<body>
<h1><%=Model.Root.Element("heading").Value %></h1>
<%=Html.Raw(Model.Root.Element("body").ToString())%>
</body>
@willprice76
willprice76 / pageless-tridion-content-model.cs
Created September 7, 2012 11:25
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");
@willprice76
willprice76 / pageless-tridion-content-controller.cs
Created September 7, 2012 11:29
Pageless Tridion Content Controller
public class DynamicContentController : Controller
{
public ActionResult Render(string url, string contentType)
{
string viewName = GetView(contentType, url);
XDocument content = (new TridionModel()).GetContent(contentType, url);
if (content != null)
{
return View(viewName, content);
}
@willprice76
willprice76 / pageless-tridion-content-routing.cs
Created September 7, 2012 11:30
Pageless Tridion Content Routing
RouteTable.Routes.MapRoute("News", "news/{*url}", new {controller="DynamicContent", action="Render", contentType="News"});
@willprice76
willprice76 / pageless-tridion-content-getcontentquery.cs
Created September 7, 2012 11:43
Pageless Tridion Content Get Content Query
public XDocument GetContent(string contentType, string url)
{
int publicationId = Int32.Parse(ConfigurationManager.AppSettings["tridion:publicationid"]);
var cpf = new ComponentPresentationFactory(publicationId);
if (GetViewType(url) == "Detail")
{
int itemId = GetIdFromUrl(url);
if (itemId > 0)
{
var cp = cpf.GetComponentPresentationWithOutputFormat(itemId, "Xml Document");
@willprice76
willprice76 / pageless-tridion-content-newslist.aspx
Created September 7, 2012 12:02
Pageless Tridion Content News List View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<XDocument>" %>
<html>
<head>
<title>News List</title>
<meta name="description" content="All the latest news" />
</head>
<body>
<h1>News List</h1>
<% foreach(var item in Model.Descendants("item")) {%>
<h2><a href="<%=Example.MvcDemo.ViewHelper.GetItemLink(item,"News")%>"><%=item.Element("heading").Value %></a></h2>