Did you know this is default in Umbraco?

by Damiaan Peeters 8. December 2013 15:18

A few days ago I got the question from a manager: “Is this default in Umbraco?” To be honest, that is a very difficult question that deserves a blog post on it’s own.  So here it is!  The answer to a general question asked to an umbraco developer: "Is this default in Umbraco?"

Short answer

It is probably a default setup on how you can work with Umbraco.  So: yes.

Slightly longer answer

It depends of course on what you call “default”.  But the developer you are asking this question, has probably implemented the things asked already a few times.  Been there, done that.  And if he hasn’t done so, he might have found a blog post or forum topic which explains how to do so.  Or maybe he has found (a free) package, which does the things considered to be default.

The reason why the developer can say it is default, is packages, blogs and extending umbraco IS default.  Without the default behaviour, you would not have a website. 

Long answer

First of all, I wrote earlier that Umbraco is not a CMS, I called it a framework.  Umbraco provides a base for you to build web applications (or websites), without trying to interfere with the developers using it.

Umbraco does not provide strict guidelines on how to setup your website.  It does not force information into predefined concepts.  As such the developer need to (sic, by default) extend the Umbraco download, in order to have a website.  The nice thing about Umbraco, is that it doesn’t limit you in how you organise everything to get things done.  It gives you a solid base where you can plug in different things.

The core of Umbraco exists out of an amount of default modules.  These modules take care of rendering your webpages, building URL’s, saving and publishing content items (nodes) and rendering backend.  These modules are “default”, but no-one would not expect otherwise from a CMS.  That's why you are not writing your own rendering engine, but instead choose a CMS. 

A lot of modules in the Umbraco Core can be replaced or extended by your own needs.  I consider replacing these modules, or adding extra functionality to modules ALSO default.  A developer familiar with the concerned topics (extending umbraco and dev’s reference), doesn’t need to know all the internals to add easy customizations to your website.  This is were a lot of power of umbraco comes from, and is to my knowledge not always easy to do with other cms’s. Extending the base is daily job, and can be considered default.

If the core is not enough, there are a lot of packages.  Packages are pieces of software which are developed by 3th parties (except for Courier, Contour and Concierge), which add extra functionality to Umbraco.  Most packages are free, some not.  Packages are build for Umbraco, and the Umbraco back-end makes it very easy to install addons.  I think we can safely say that most Umbraco installations use packages.  This makes me believe the Umbraco Packages are default.  If someone would try too argue against, consider that there are packages which are now included (or parts of it) into to core (like uGoLive, uComponents, …).

One of the great side effects of having such a Robust core is that a lot of package creators, implement the same robust principles in there software.  This makes it for packages developers easy to plug into events of 3th party packages, and “customize” this further.

If you read up till here, you might wonder: all this customization sounds like pretty expensive.  I can’t talk for other companies, or what they are charging for certain functionality.  In our experience, Umbraco offers a lot of extendable default functionality speeding up development.  This gives the customizations in question a much higher return on investment, compared to Umbraco-less solutions.

So what do you think?  What do you consider "default" in umbraco?

Language in HTML tag

by Damiaan Peeters 4. September 2013 12:48

According to W3 we should put a language attribute in our HTML tag. I’ve seen a lot of ugly and unmaintainable solutions for putting language tags in the HTML.  With MVC the problem is less

With ugly I mean the following: you don’t want to encapsulate one tag in a macro.  Do you?  As you might know, I hate inline macro’s anyway.

<umbraco:Macro language=”cshtml” runat=”server”>
<html lang=”@Model.Lang”>

with unmaintainable I mean:

<html lang=”<umbraco:item field=”lang” runat=”server” recursive=”true”/>”>

You don’t want to allow the user to choose and mistype the language.   Certainly because you already set the culture on the root node?

Set culture on root node

If you haven’t you should.  It’s not difficult.  Right click the home page node, and choose “Manage hostnames”.


The best solution?

If you have set the culture on the parent node, you can reuse default “CurrentCulture” ASP.net object to pick up the language.  I’ve added the namespace so that it works for less technical readers, but you could strip that out off course.

<html lang="<%= System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.ToLower() %>">

If you use MVC in umbraco it’s even more readable:

<html lang=”@System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.ToLower()”>

How do you solve this?  Let me know in the comments!

Umbraco and embedded macro scripts

by Damiaan Peeters 11. January 2013 08:58

It is possible to use Embedded macro scripts in master pages.  You know:

<umbraco:Macro runat=”server” language=”cshtml”>

I’ve seen a lot of these chunks of code in masterpages.  Although you might LOVE Razor, there is no reason for you to do this!   

First of all, you could solve the previous line simple with a <umbraco:Item /> tag in your master page.  Secondly, Umbraco released version 4.10 with MVC capabilities. So you don’t need to use the Masterpages anyway.  Do you? Thirdly, u can still use inline code.  I know the documentation says it’s not a recommended way, but it’s fast and for easy master page related things I think perfectly fine. <% if(condition) umbraco.NodeFactory.Node.GetCurrent().GetProperty(…).Value %> This doesn’t involve a creation overhead for each Razor macro which is being called.

But here are my personal reasons why I don’t like them:

  • Visual studio problems: if coding embedded macro’s in visual studio you have
    • no intellisense
    • bad syntax highlighting
    • impossible errors & bizar warnings
    • automatic formatting shortcut screws up everything. In VS, you can use CTRL + K , CTRL + D to format your code automatically. Your embedded macro’s will probably screws up regularly.
  • Hard(er) to configure cache parameters.  Did you ever tried to cache by page or by member?
  • Having to macro’s running next to each other:

    <umbraco:Macro runat="server" language="cshtml">
  • You can’t set a break point and really DEBUG what might be going wrong in your code.
  • When you ARE debugging
    • you end up in separate files and you do not know which masterpage you are exactly debugging
    • you can and will change - by accident – temporary generated razor scripts

Most of the time I use these rules on how we use Razor Macro’s in Umbraco:

  • Create separate files in the MacroScripts folder. 
  • If performance is importance convert Model to DynamicNode instead of working with DLR objects
  • Add @Inherits & @using umbraco.MacroEngines  to optimize Visual Studio Experience
  • Use Helpers where possible
  • Extend @Library or create own extensions in App_Code or even better: a custom .Net dll with your code precompiled
  • Choose between @umbraco.library.GetDictionaryItem(“theDictKey”) and @Dictionary.theDictKey and don’t use both.
  • Follow coding standards which are normally applied in normal .Net code.  For razor I prefer { on the same line (see post of scottgu introducing Razor).  But don’t mix!
  • If you really need an embedded macro and want a break point, use  @{                System.Diagnostics.Debugger.Break(); }

Oh.  And check out the umbraco development guidelines on our, they are there for you to read.

What do you think?  Do you agree?  What are your best practices for umbraco and Razor macro’s.


Certified Umbraco Master, Part of Umbraco Certified partner comm-it, .Net and Azure developer, seo lover. Magician in my spare time.

Month List