Umbraco Cheatsheet

Here’s a collection of links and tips for working with Umbraco. I’ll try to keep this up to date.

How do I run a custom controller

You want to use what Umbraco calls either “custom controllers” or “route hijacking”.

https://our.umbraco.org/documentation/reference/routing/custom-controllers

It looks for a controller matching the Document Type name, and then an action matching the Template name, with a fallback to Index().

Make sure it inherits from Umbraco.Web.Mvc.RenderMvcController.

How do I handle a form post?

Check out what Umbraco calls “Surface Controllers”

https://our.umbraco.org/documentation/reference/routing/surface-controllers

Make sure it inherits from Umbraco.Web.Mvc.SurfaceController

How do I render a rich text field with a macro?

If you’re using an Umbraco ORM for typed models, you might find rich text fields with macros rendering the macro XML instead of expanding.

1
2
3
4
5
6
public string RenderMacros(string richText, int documentId)
{
var withMacros = umbraco.library.RenderMacroContent(richText, documentId);
var withLinks = TemplateUtilities.ParseInternalLinks(withMacros);
return withLinks;
}

You’ll also want to call ParseInternalLinks which converts hrefs like /{localLink:1085} into the real URLs.

See: https://www.mattburkedev.com/new-application-slash-tree-in-umbraco-7-backoffice-not-showing/ for a convenient extension method.

How do I get typed models in my view?

May I humbly suggest using The Nerdery’s Umbraco Vault project?

How do I create a custom tab in the back office (7+)?

Its called an “application” or a “section” and sometimes a “plugin”. Those terms should help your Google searching.