Question:

Modelling one-off pages with DD4T

Autumn: 6 days ago

My web application has a number of one-off pages, by which I mean a page whose contents does not follow a standard layout, and the content does not fit a standard schema. These are typically simple single page forms and the like.

I decided to use a generic schema to model the contents, where key-value pairs can be used to define any number of bits of text, links and so on. This prevents the need to create a new schema for each one-off page, avoiding schema bloat (the content should be managed by editors).

The real problem comes with defining a view/layout for the content on the page. I also do not want to create a new page and or component template, so I am using generic PT/CTs, which map to views in DD4T, however I need a totally separate view for each page/CP.

Whats the best way to manage this in Tridion/DD4T?

Answer:
Lucy: 6 days ago

By default the view for DD4T is determined by either the name of the Template or it can be specified on the Component or Page Template Metadata, here you can also set a different controller.

If you specify a different controller on your Template and then in that controller override GetView() to read the view from the Component Metadata instead, you have the option to set a separate view per Component.

See TridionControllerBase.cs (https://code.google.com/p/dynamic-delivery-4-tridion/source/browse/trunk/dotnet/DD4T.Mvc/Controllers/TridionControllerBase.cs) in Google Code, for the default handling of the view in lines 42 (Page) and 64 (ComponentPresentation).