5 Ways to maintain quality in Tridion Templates

April 11th, 2012 | Posted by Robert Curlette in Tridion

Recently while updating an old VBScript Component Template I was surprised at seeing several bad practices in place and began to update the template. When we update a template we should always try to clean it, add comments, etc and leave it in a better state than we found it. Here I will give some tips for keeping things in order:

1. Good indentation – Tridion Templates open in their own browser window. Don’t edit the template there – DON’T DO IT! IT can be tempting, and maybe save you 30 seconds of copying it to your text editor – but you’ll screw up your indentation and make it impossible to follow for your other colleagues who are using text editors for template development.

Update: Set Notepad + to use spaces instead of tabs. Thanks Ingmar for the comment! http://stackoverflow.com/questions/455037/notepad-tabs-to-spaces

2. Access Component Presentations in Page Templates, Fields in Component Templates. Looping through Component Presentations in the Component Template is bad practice, slows the template down, ais not consistent with data model of Tridion and doesn’t make sense.

3. Use local variables in functions and subs. Using global variables in functions and sub-routines is bad practice. Respect the scope of a function or sub and pass in all variables, otherwise, it makes it very difficult to debug later.

4. Set variables when you declare them. For example, in VBScript use

Dim body : body = ""

5. Consistency with if conditions. Don’t write if statements on 1 line – especially within a nested if in VBScript. Makes it terribly difficult to follow.

I hope we can all establish good coding practices and follow them to keep our templates clean and in good health!

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

4 Responses

  • Ingmaru says:

    Nah, editting in the html gui is fine, as long as you use REAL tabs, not hit TAB (as if we haven’t tried that once ;)) just copy/paste a real TAB from somewhere else in the template 🙂 (WARNING: this is expert mode, we are trained proffesionals, do NOT try this at home!)

    Another one: never EVER let a Component Template be able to output INcomplete xml/html! Always close all tags you opened and never close tags you did not open. When using if/then, make sure there is always an else clause (or another TemplateIf)

  • robert curlette says:

    LOL, Ingmar, You’re a closet template developer using the Browser Window?! Wow – I am surprised to hear your tip on tabs – interesting and I guess the advice is to set up our text editors to use spaces instead of the ‘tab’.

  • Although I am definitely guilty of editing in the Template window, which should be allowed, just make sure you try to establish consent in the use of tabs or spaces (Common issue even in C# templating…) I am all about the 4 spaces instead of tabs.

    Another important one with VBScript is not to go crazy on functions in functions using functions from another TBB in another TBB (unless you enjoy long sweaty treasure hunts).

    Take it easy on the use of constants (in TBB’s) usually it starts of as a great plan of re-usability and maintenance, but it ends up as a nightmare.

    This also brings up the use of URI’s (in Constants), just bad…

    And finally, avoid creating all kinds of HTML in functions (especially when they are called from another function, from another functions, etc…

    By the way, I have been guilty of all these transgressions myself as well. In Tridionland no developers are innocent!

  • Alvin says:

    Add “reduce hard-coded values” to the list! We should put keep content and tcm-ids out of templates as much as possible. 🙂

    Now what was I doing again? Oh yeah. Searching for more RC GUI extensions goodness…



Leave a Reply

Your email address will not be published. Required fields are marked *