Skip to main content

Posts

Showing posts from November, 2015

A DD4T.net Implementation - Rendering One Component Presentation Only

DD4T 1.3 comes with a few Html extension methods that allow us to render Component Presentation inside a Page Razor view using different ways of filtering through the list of ComponentPresentations on the IPage object: RenderComponentPresentations() -- renders all ComponentPresentations on the page; RenderComponentPresentationsBySchema() -- renders only ComponentPresentations whose Component is based on a given Schema title or TcmUri; RenderComponentPresetnationsByView() -- renders only ComponentPresentations whose ComponentTemplate uses a given view name or has a given TcmUri; There is however, no helper method that allows the rendering of just a simple plain ComponentPresentation, yet sometimes that is exactly what I would need. Below is one such Html extension method that calls the rendering of only the given ComponentPresentation object: public static MvcHtmlString RenderComponentPresentation ( this HtmlHelper htmlHelper, IComponentPresentation cp) { if

A DD4T.net Implementation - Custom View Locations

The entire need to have custom view locations started when I implemented my Component controllers as separate classes. By default DD4T .net comes (or expects) one ComponentController class. In the Component Template metadata, we can specify the controller, action and view names to execute and use when DD4T renders a Component Presentation on this Component Template. Since I have several Component controllers, for the sake of clarity and separation, I implemented several controller classes -- one for each Component controller I have. For example, I have a DeviceController that renders Component Presentations based on Schema Device . DeviceController defines a simple Index method that is mapped from the Component Template metadata. public class DeviceController : MyControllerBase { public ActionResult Index ( int? publication, int? component, string view) { // code goes here } } The moment I executed my code, I got ni

A DD4T.net Implementation - Little Bit of Linking

In order to resolve links, the Linking API must be invoked on the Content Delivery server, when the page is being quested. This is also called frying. This ensures that links are always displayed only if the target page is available (i.e. published). In DD4T, when we resolve a Component link, we call one of the ResolveLink methods of the ILinkFactory factory. public interface ILinkFactory { string ResolveLink ( string componentUri); string ResolveLink ( string sourcePageUri, string componentUri, string excludeComponentTemplateUri); ICacheAgent CacheAgent { get ; set ; } ILinkProvider LinkProvider { get ; set ; } } Since we are using strongly-typed models, it means we can easily include this logic in the model itself. This means we can provide a lazy loaded property on the ModelBase class that calls the ILinkFactory.ResolveLink method using the Id  property of the model. public class ModelBase : IComparable<ModelBase> { pub

A DD4T.net Implementation - Making URLs Case Insensitive

URLs in DD4T .net v1.3x are case sensitive. The issue is more of an annoyance than anything because Tridion Content Delivery provides APIs that perform findByUrl in a case-insensitive way. However, that doesn't help us because the default TridionPageProvider  that comes with DD4T .net uses the PageURLCriteria , which case-sensitive. My solution is to extend the TridionPageProvider and override the GetContentByUrl method. In my code I'm using the PageMetaFactory.GetMetaByUrl method, which is case-insensitive. public class MyPageProvider : TridionPageProvider, IPageProvider, IProvider { public new string GetContentByUrl ( string url) { string content = string .Empty; PageMetaFactory factory = new PageMetaFactory(PublicationId); IPageMeta pageMeta = factory.GetMetaByUrl(PublicationId, url); if (pageMeta != null ) { TcmUri tcmUri = new TcmUri(pageMeta.PublicationId, pageMeta.Id, 64 , 0 ); co