Why Umbraco rocks - alternative templates
The main building blocks of umbraco are as you know document types and templates. When creating a document types the umbraco interface will give you the options to also create a templates that is then setup as the default template on that document type. If you open up the details of a document types you’ll be able to see the ‘allowed templates’ part on the info tab.
Document types aren’t limited to 1 template and this is great! You can easily swith to an ‘alt template’ by simply editing the url of your page.
So if you would have a homepage.aspx and you want to apply templatex on it you can do this by changing the url to
homepage/templatex.aspx
another option is this
homepage.aspx?alttemplate=templatex
In the beginning I didn’t use alternative templates that much but it’s a great way to keep your content section clean.
For example an email to a friend page, instead of making this a new documenttype and adding it to the content en then passing the id of the page you want to email…
You can simply add an email to a friend template and call it up as an alternative template, that way you won’t need to pass the nodeid because you are still on the same node !

Hi Tim,
This is a useful tip.
I think in Umbraco v4 this could be further extended:
What I’d really like to see in Umbraco 4, which uses .NET Master Pages, is the ability to dynamically change the master page (programatically). This is often called “Dynamic Master Pages”
http://bdwebster.com/2008/02/15/dynamic-master-pages/
http://mishler.net/2006/04/10/Dynamic Master Pages.aspx
The idea would be that rather than change the template, you change the master template (dynamically, using C# embedded in the ASP)
But to get this functionality I think a modification is required to the umbraco source code…
It’s also an excellent way of making simpler, cleaner versions of a page used for “Print this page” links.
Just make a clean template and add ?alttemplate=templatePrintable to the current URL.
Hiya Tim nice post for beginners.
When I first started using umbraco I didn’t know about altTemplates when I was developing my website wizard package.
But when I come to do the new updated version of the package to work with V4 of Umbraco, the physical node for google sitemap and the email a friend will be dropped and replaced with altTemplates.
Warren
Hi, alternative templates are great, but be aware:
Umbraco doesn’t check if template is allowed for specific page!
If you use something like autoform and don’t any authorization to edit page, anyone can then edit your page, if know right name of your edit template simply by adding ?alttemplate=edit_template_name.
Petr
@Petr: That’s intentional as it would be a false trust. Security shouldn’t be based on what templates are allowed, but more on validation user credentials which umbraco can’t handle automatically in the template switching layer. So you should always validate credentials in your business layer.
Regarding switching templates with AutoForm you’d get an exception unless all your templates has the exact same properties with same aliases.
/n
@Hartvig: I agree with you, that security should be based on users credentials.
But sometimes this isn’t possible if umbraco doesn’t check allowed templates.
Sample:
When you create autoform template for adding blog comments, you want to allow all users to use this template. But when umbraco doesn’t check if this (blog comment template) is allowed for another document type (for example news) and by using querystring evil user can assign this (free for all) template for news documenttype. Then he can add new news item using this template, or if documenttype in macro is specified add comment to existing news.
Petr
Is it possible to use the template name, rather than alias?
Or do I need to use urlredirection to fix this?
Laurie
Действительно! Это всем пригодится.