Skip to main content

Posts

Showing posts from 2015

A DD4T.net Implementation - Pagination (AJAX)

This is the third and last post on the topic of implementing a pagination solution for lists of Dynamic Component Presentations retrieved by a query. If you haven't already done so, please read the first two posts to put things in context: Pagination - Models Pagination - Views This post deals with client-side Javascript code performing the AJAX call to the server-side code and displaying the returned HTML. In the current architecture, the server-side components render a snippet of HTML (i.e. the only piece of markup that changes between two page iterations). I use Javascript (JQuery) to replace the content of a container DIV with the HTML returned by the DD4T server-side partials. Since we receive rendered HTML back, it is quite simple to perform the DIV content replacement. No other rendering, parsing or processing is necessary as if we had received JSON back from the server. I chose this approach because it fits better with the Tridion and DD4T architecture. I can easi...

A DD4T.net Implementation - Pagination (Views)

In previous post Pagination (Models) , I presented a way of modeling the server-side code to display dynamic lists of Dynamic Component Presentations (DCP) using AJAX. In this post, I present the server-side view logic in context of MVC .net architecture and using Razor CSHTML views. As presented in the previous post, the Controller creates a model class that contains the paginated list, and it then attaches this model to the ViewBag. In the example it was DeviceController, that created model DocumentPartial which contained a paginated list of documents. We now need to display this list of paginated items in a Razor view. In order to make the logic reusable and succinct, I implemented the paginated view as partial view. The Component view corresponding to the controller includes the partial view and passes to it the model previously saved in the ViewBag. This makes the partial view generic and reusable from other contexts. To continue our earlier example, the view corresponding...

A DD4T.net Implementation - Pagination (Models)

This post adds pagination capabilities to an AJAX Dynamic Component Presentation (DCP) presented in an earlier post Rendering Only a Partial for AJAX . The use case is the following: we have a controller that displays a list of DCPs in a paginated way. Due to the dynamic nature of this list, the list of DCPs should be rendered as a partial using AJAX. This implies that an actual AJAX request is made to the controller, which triggers only the list of DCPs be recalculated and served back. The paginated AJAX URL produces HTML directly, therefore the Javascript logic can simply replace the container div 'innerHTML' with the markup received from pagination. A whole page reload is thus not necessary. Additionally the list of DCPs can be sorted before being paginated, but about that in a later post. This post descries the server-side model builder that generated the paginated list of models. In a subsequent post I will present the server-side views that render the same and the cli...

A DD4T.net Implementation - Navigtion Utils

In the previous posts Navigation and Navigation (part 2) , I presented the NavigationFactory class and the object model obtained by deserializing the navigation XML. In this post, I will present simple examples of creating breadcrumb and navigation structures. Breadcrumb When rendering a breadcrumb trail, we start by locating the NavigationItem in the navigation object model corresponding to the current page, and then we follow the "ParentItem" relation to go up until the navigation root. We retain each NavigationItem that we encounter in this traversal. Finally, the breadcrumb trail is the reversed list of these NavigationItems. The following code is part of the NavigationFactory and returns an array of NavigationItem objects corresponding to the breadcrumb trail. public NavigationItem[] GetBreadcrumb (NavigationItem page) { IList<NavigationItem> result = new List<NavigationItem>(); if (page != null ) { do { ...

A DD4T.net Implementation - Navigation (part 3)

Check out the previous posts about the NavigationFactory: Navigation and Navigation (part 2) . I presented a way to deserialize the navigation XML into an object model and then serve it through a factory class that uses caching. In this post, I will present a simple way of locating a certain node in the navigation object model. Locating a NavigationItem is done by comparing it in some way to a given identifier. The most natural way is to retrieve an item by its TcmUri. In order to do so, I defined the following method on the INavigationFactory interface: NavigationItem GetItemById (Navigation navigation, string tcmUri); The implementation of this method traverses the Navigation object passed as parameter and applies a Comparator to it, hoping to identify the given tcmUri. The method calls helper method FindItem that performs the recursive traversal of the Navigation object model. public NavigationItem GetItemById (Navigation navigation, string pageUri) { if...

A DD4T.net Implementation - Navigation (part 2)

In previous post, Navigation , I presented the foundation for deserializing the navigation XML into an object model. In this post, I'll continue presenting the NavigationFactory class and the integration with caching. The NavigationFactory class is a singleton wired through dependency injection (such as Ninject) that uses caching to serve navigation object model for a given Publication. [Inject] public virtual ICacheWrapper CacheWrapper { get ; set ; } public Navigation GetNavigation () { string publicationUrl = UriHelper.GetPublicationUrl(HttpContext.Current); string key = GetKey(publicationUrl); Navigation navigation; object cacheElement; if (!CacheWrapper.TryGet(key, out cacheElement)) { string virtualPath = publicationUrl + "system/navigation.xml" ; string filePath = HttpContext.Current.Request.MapPath(virtualPath); navigation = ParseXml<Navigation>(filePath); SetParent(navigation); ...

A DD4T.net Implementation - Navigation

Most of the websites I have worked on already existed before upgrading them to DD4T. This means the navigation has already been implemented, usually as means of publishing an XML file from Tridion (most always called navigation.xml ;-) ), and then rendered dynamically at request time by means of XSLT transformation. This setup makes it quite easy to implement navigation in DD4T. I always try to reuse what I have, and the existing navigation.xml is a perfect candidate. We can reuse the Tridion template and Template Building Block that generates the navigation without any modification. The generated navigation.xml can be even published to file-system, so other parts of the website can still use it. Alternatively, we can store it in the Content Delivery DB. The approach for generating navigation in DD4T relies in creating an object model from the navigation XML by deserialization, then caching it for faster performance. Everything is wrapped inside a singleton factory wired through ...

A DD4T.net Implementation - Taxonomy Performance Issues

Retrieving Classified Items for Multiple Keywords My intention when retrieving the classified items for a taxonomy is to resolve the entire taxonomy (i.e. all its keywords) first, and then cache it. This way, retrieving the related content for a given keyword would be very fast. I described this approach for DD4T Java in post  Retrieve Classified Items for Multiple Keywords . There is one issue with that approach in .NET -- it is not standard API and one must write their own Java Hibernate code to retrieve the classified items. In DD4T Java that is not an issue, but in DD4T .NET, exposing the custom Java logic to the .NET CLR is not easy. It would involve writing some JNI proxy classes to bridge the two virtual machines. I just don't feel like writing that code. Enter the second best approach -- resolving classified items on-the-fly, for one keyword at the time, on demand, as described in post  Taxonomy Factory . Retrieving Large Taxonomies Another performance issue i...

A DD4T.net Implementation - Taxonomy Factory (part 2)

In a previous post, I presented the Taxonomy Factory and a way of retrieving taxonomies and keywords from Tridion. In this post, I will present more functionality about retrieving content tagged against a certain Keyword. string [] GetRelatedContent (IMyKeyword keyword); string [] GetRelatedContentBySchema (IMyKeyword keyword, string schemaTitle); string [] GetRelatedContentBySchemaAndMetadata (IMyKeyword keyword, string schemaTitle, string metadataKey, string metadataValue); All these methods return a list of TcmUris representing Components or Pages that are tagged with the given Keyword. Method GetRelatedContent is the simplest of these methods, and it returns the TcmUris of all items that are directly tagged with the given Keyword. The implementation uses the Tridion.ContentDelivery.Taxonomies. TaxonomyRelationManager to retrieve the related content: private TaxonomyRelationManager manager; public MyTaxonomyFactory () { ...

A DD4T.net Implementation - Taxonomy Converter

In a previous post, I presented the Taxonomy Factory and a way of retrieving taxonomies and keywords from Tridion. One of the promises I made in there was to explain the conversion process from a Tridion Keyword to a specialized class MyKeyword, a subclass of DD4T.ContentModel.IKeyword. The DD4T IKeyword class does not provide a way to navigate the taxonomy downwards -- it only provides a ParentKeywords property. Therefore, I created IMyKeyword: public interface IMyKeyword : IKeyword { IList<IMyKeyword> ChildKeywords { get ; } IMyKeyword ParentKeyword { get ; } new IList<IMyKeyword> ParentKeywords { get ; } } Its accompanying implementation class is quite trivial: using dd4t = DD4T.ContentModel; public class MyKeyword : dd4t.Keyword, IMyKeyword { private IList<IMyKeyword> _childKeywords = new List<IMyKeyword>(); public IList<IMyKeyword> ChildKeywords { get { return _childKeywords; } } priva...

A DD4T.net Implementation - Taxonomy Factory

I have noticed that in all my recent projects, there is a strong need for an easy and well performing way of handling taxonomies. Functionality ranges from being able to read a Keyword in a taxonomy, to traverse the child/parent relationships, to read metadata on a Keyword and also to read related Components tagged against a Keyword. In order to provide these features, I implemented a DD4T factory that deals with Tridion taxonomies. Namely, I created the ITaxonomyFactory that defines certain method signatures. I'm using Ninject to bind the interface to an actual implementing class, so using this in DD4T context is trivial. public interface ITaxonomyFactory { MyKeyword GetTaxonomy ( string taxonomyXmlNameOrUri); MyKeyword GetKeywordByUri (MyKeyword root, string uri); } The factory class uses the TaxonomyFactory and TaxonomyRelationManager to interact with the data published to the Content Delivery database. Method GetTaxonomy takes either a Taxonomy XML name, ...