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
using System; | |
using System.ComponentModel; | |
using Tridion.ContentDelivery.Web.Utilities; | |
namespace Tridion.Extensions.ContentDelivery.Web.UI | |
{ | |
/// <summary> | |
/// Custom ComponentLink class, to replace the Tridion.ContentDelivery.Web.UI.ComponentLink | |
/// class with an added property to set query string parameters | |
/// </summary> |
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 static string GetViewType(string url) | |
{ | |
return url.Contains(".html") ? "Detail" : "List"; | |
} |
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
private string GetView(string contentType, string url) | |
{ | |
return "News" + TridionModel.GetViewType(url); | |
} |
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
<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> |
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
<%@ 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> |
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"); |
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 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); | |
} |
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
RouteTable.Routes.MapRoute("News", "news/{*url}", new {controller="DynamicContent", action="Render", contentType="News"}); |
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 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"); |
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
<%@ 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> |
OlderNewer