Nibble

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.

image

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 !

12 Comments so far

  1. Adz on August 9th, 2008

    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…

  2. Soeren Sprogoe on August 9th, 2008

    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.

  3. Warren Buckley on August 9th, 2008

    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

  4. Petr Snobelt on August 11th, 2008

    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

  5. Hartvig on August 11th, 2008

    @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

  6. Petr Snobelt on August 12th, 2008

    @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

  7. Laurie on January 7th, 2010

    Is it possible to use the template name, rather than alias?

    Or do I need to use urlredirection to fix this?

    Laurie

  8. DDubyah on November 29th, 2010

    Really useful tip. We’re just starting to work with Umbraco so this is good to know. Thanks.

  9. hack on March 11th, 2014

    WOW just what I was looking for. Came here by searching for
    cheat

  10. martinique on October 6th, 2015

    Thanks for your personal marvelous posting! I definitely enjoyed reading it, you could be a great
    author. I will ensure that I bookmark your blog and will often come
    back at some point. I want to encourage you to definitely
    continue your great job, have a nice holiday weekend!

  11. best free vpn service on October 14th, 2015

    Hello, this weekend is good in support of me, since
    this occasion i am reading this great informative post
    here at my house.

  12. visit the website on January 20th, 2016

    This is my first time go to see at here and i am
    actually happy to read everthing at single place.

Leave a Reply