I have a template that has grown to be over 1200 lines long. I need to bring down the size to make it more maintainable and manageable. The way it works is this.. The template is used to create product pages. Product information is passed to it. So, the template has a number of conditionals based on the product component used to build the page with different html.

I'm thinking that a solution may be to create c# UserControls, pass the data to the usercontrols and build out the html within the usercontrols.

Basically, (if this was .net) I would want to break the template into a number of related class objects for easier maintenance.

What would be the best approach?

  • What template language are you talking about exactly and what version of SDL Tridion is it? Supplying more detail on that will help in getting a better answer. Commented Jan 16, 2015 at 14:06
  • Have you considered the Razor Mediator? I'm assuming you could be using Compound Templating, but please update your answer to get better information! We've found that a lot of the work that used to need to be done with C# Templating code can be achieved simply in the expanded API that Razor templating gives you access to (compared to DWT). You can still produce User control tags with it too, as Nick recommends. Commented Jan 16, 2015 at 14:07
  • Presumably you have already taken some measures to try to get the code down from 1200 lines. What have you done already, and how has this led you to think of a solution based on user controls? The point is that sure, you can split up the logic in the web application, but Tridion also offers many possibilities to do this within your templating. So what have you tried? Commented Jan 16, 2015 at 14:11
  • As most people already said, the best answer to your question depends on the functionality in those 1200 lines. But in general the Tridion CMS (and its modular template model in particular) favors using composition as a re-use model over using inheritance. Examples of composition are the visual blocks that Bjorn mentions (which are a general Tridion concept) or the Template Building Blocks that Nick talks about (which are a concept of modular templates). Either way: add more details if you'd like to get a more specific/concrete answer. Commented Jan 19, 2015 at 19:22
  • I've been thinking about many of the above comments..particularly composition vs inheritance.Inheritance would be easier for me to implement, but would hide page data on the back-end where the web producers would be unable to access. The template in question(1200 lines long) is a Razor template that based on component data, injects html to build out the page.That html should probably reside in a component somewhere.If that were the case, I'm assuming I would need to use TBB's to figure out which component(and its html) to bring in to build out the page instead of placing the logic in the tplt?
    – Freq
    Commented Jan 30, 2015 at 18:53

3 Answers 3


As per your suggestion in the question, there is nothing wrong with rendering a User Control tag and passing the data from Tridion into it, or publishing an XML file from Tridion with the data and have it feed the User Controls. I would do this in select cases, for example: rendering the navigation, or complex content types, such as, surveys or forms.

Another approach is to have the logic of the Page Template placed inside C# TBBs, or if the scenario permits, divy up the page into various Component Presentations which would have Component Templates take care of rendering each region.

  • I am investigating keeping the basic html in the template, then pushing the component's xml into the usercontrol and performing logic there, based on the contents of the xml.
    – Freq
    Commented Jan 20, 2015 at 15:38

Assuming this is compound templating and we are talking about a page template I would suggest breaking up the page template into separate visual blocks to be rendered as component presentations (as is the "standard" way of building up pages in SDL Tridion).

Having one page template do everything means you are in code implementing a lot of variability that the SDL Tridion page->component presentation model provides out of the box (hence the large code volume).

If this is not an option implement a dispatcher mechanism: based on the properties of the component you would choose which "part" of the template to render with and you would render with the corresponding template via a call to

engine.RenderComponentPresentation(componentUri, componentTemplateUri)

In Addition to the current answers and assuming you are using compound templating and the "code" here is in c#.

You could look to break the Product and it's dependent entities in to the c# custom classes. And use it in your templating .net solution. this way you could easily manage the smaller classes.

  • 2
    If you follow this approach make sure to have all your classes in the same project as your templates. If you use a separate project for your classes you will get an error that they're not in the GAC. With a separate project you would need to put them in the GAC or use ILMerge to create 1dll from your multiple projects and then use tcmuploadassembly to put it in Tridion.
    – robrtc
    Commented Jan 19, 2015 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.