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 !

25 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.

  13. Stefaan Christiaens on February 27th, 2017

    Alt templates, why did I never hear about this in the 4 years I am working with Umbraco… Could have made my life so much easier. Thanks for yet another excellent post.

  14. try this out on November 10th, 2017

    grea issujes altogether, you just received a new reader.

    What could you suggest about your publish that you just made a few
    days ago? Any sure?

  15. Kayleigh on December 7th, 2017

    Thhis blog was… how do I say it? Relevant!!
    Finally I’ve found something which heled me. Thanks a lot!

  16. Toney on December 11th, 2017

    Pretty! This has been a really wonderful article. Thank you for supplying these details.

  17. Skye on December 24th, 2017

    Really when someone doesn’t be aware of afterward its up to other users that they will
    assist, so here it takes place.

  18. mushroom allergy truffles on January 30th, 2018

    Fantastic items from you, man. I have bear in mind
    your stuff previous to and you are simply too excellent.
    I actually like what you’ve obtained here, certainly like what you’re
    saying and the best way during which you say it. You make
    it enjoyable and you continue to care for to stay it sensible.
    I can not wait to read much more from you. This is actually a wonderful website.

  19. www.brodun.com on February 25th, 2018

    These are the most sought after Jobs on the world wide web.

  20. fake Diplomas that Look real on February 26th, 2018

    I constantⅼү spent my half an hour to read tһis website’s posts aⅼl the time ɑlong with a
    cup of coffee.

  21. minions 2 on March 29th, 2018

    I am not certain the place you’re getting your info, but great topic.
    I needs to spend a while finding out much more or figuring out more.
    Thank you for magnificent info I was on the lookout for this info
    for my mission.

  22. Best Internet provider in Myanmar on April 11th, 2018

    Unquestionably imagine that which you stated.

    Your favorite justification appeared to be at the web the easiest thing to take note of.
    I say to you, I definitely get irked at the same time
    as folks think about concerns that they plainly do not understand about.
    You controlled to hit the nail upon the top and defined
    out the whole thing with no need side effect , other folks
    can take a signal. Will likely be back to get
    more. Thank you

  23. Chet on April 15th, 2018

    Having read this I thought it was really enlightening.
    I appreciate you spending some time and energy to put this informative
    article together. I once again find myself spending a significant amount of time both reading and posting
    comments. But so what, it was still worth it!

  24. Ericka on April 15th, 2018

    I am really enjoying the theme/design of your web site. Do you ever
    run into any web browser compatibility issues?
    A number of my blog readers have complained about my website not
    operating correctly in Explorer but looks great in Firefox.
    Do you have any tips to help fix this issue?

  25. Maria on May 17th, 2018

    I do not even know how I stopped up here, however I assumed this post used to be good.

    I do not recognise who you’re however definitely you are going to a famous blogger if you aren’t already.
    Cheers!

Leave a Reply