Skip to main content

Posts

Showing posts with the label MVC

Error pages in DD4T (404 and 500)

In DD4T the 404 page can be retrieved as below, Override the Action Page, and when the Page is null return the NotFound Action. In the NotFound action, Query the Broker for the 404  page and return the view. The 500 Error page can be throw from the Global level as below, when error occurred handle it the global level and return just view with error information

Handling images and on the fly re-sizing in DD4T

When it comes with DD4T we have plenty of control on the data and we can decided on how we wanted the page to be rendered. The traditional approach of having difference size of same image is replaced in DD4T to have one single image and generate the thumbnail on the fly. In this approach, we will have only one image published in tridion, and rest will be created on the fly based on the request. Just by adding below configuration on the web.config modules session will enable this feature <modules runAllManagedModulesForAllRequests="true">   <add name="BinaryModule"         type="DD4T.Web.Binaries.BinaryDistributionModule" />  </modules> The BinaryDistributionModule process the request as below Process the Binary Request Check if the file is already in the file system. If file is available compare the last published date of the binary against the broker. If the file is updated, update the existing file in the file system....

DD4T: Customizing RenderComponentPresentation

Sometime when we work with Component presentation, we might come up with the scenario to have customized RenderComponentPresentation, when we deal with Area/View or splitting view into more organized structure. We can fetch and send the area from the Template. Currently DD4T doesn’t allow injecting the ComponentPresentationRenderer, instead it allows us to write our own renderer and call it along with RenderComponentPresentation as below The custom ComponentPresenationRenderer can be created based on the scenario, so when we use the area, we could have the custom ComponentPresentation as below SDL Reference implementation, customized Renderer beautifully and implemented the Renderor to use Area view concept.

Dynamic Publication Resolving in DD4T

DD4T is a great framework which would give you everything in place what you basically needed. Here we will see how we could resolve the publication based on the URL,  when we work with multiple publications accessing same web site, our DD4T would need to query dynamically to different publications. Many times it can be based on URL, based on the domain or language we could resolve the publication. It’s obviously up to us how we implement it. By default the DD4T framework queries the publication that we have mapped in the key: <add key="DD4T.PublicationId" value="7" /> or keep it 0 to query all publications We can make it dynamic simply by implementing the IPublicationResolver class Step 1: To resolve publication dynamically, we can write a class that implement DD4T.ContentModel.Contracts.Resolvers.IPublicationResolver namespace Indivirtual.DD4T.Mvc.Resolver { public class SitePublicationResolver : IPublicationResolver { ...