Umbraco Flavored Markdown (UFM) label template cheat sheet

UFM has been changing so rapidly it's been hard to keep on top of the changes. But now, with syntax settling down and more options than before it's time to recreate a cheat sheet for modern Umbraco Flavored Markdown!

, by Joe Glombek

This is the UFM version of my AngularJS Filter Cheat Sheet (for Umbraco 13 and below), with the same examples where possible, tested against Umbraco 17.7.1. For everything else, see the UFM documentation, or the state of UFM in v14.1 if you're on an earlier version.

The examples are live, rendered by Umbraco's own UFM code via the UFM Playground: try editing them, or open them in the playground to change the values too. Where there's a choice, I've preferred the expression syntax (${ }) over components.

Components, expressions and filters

UFM gives you two ways to pull a value into a template:

  • Components, like {umbValue: heading} (or its shorthand, {=heading}), render a value or look something up. Some things, like the name of a picked page, can only be done with a component.
  • Expressions, like ${ heading }, are a sandboxed subset of JavaScript, so they can do a bit more, like maths, conditions and fallbacks.

Either way, you can include fixed text around them (but maybe less wordy, eh?):

Filters transform a value, like stripHtml for rich text or truncate for long text. They work with both components and expressions, but how you apply one depends on the syntax:

  • Component: after a |, with any arguments after colons: {umbValue: bodyText | stripHtml | truncate:35}
  • Expression (piped) after a |: ${ bodyText | stripHtml }
  • Expression (function): call it like a function, with the value first (and nest them to chain): ${ truncate(stripHtml(bodyText), 35) }

I tend to prefer the function syntax for expressions as I find it more readable and reliable.

⚠️ Don't use | with arguments in an expression (${ bodyText | truncate: 35 }, which at the time of writing appears in the docs). There's no error, but the argument is silently ignored.

Block labels

When you're configuring a block type in a block list or block grid, you're provided with a "Label" field. You can just type some plain text in here, but using UFM is where it really shines.

Custom columns in collections (what we used to call list views) have a UFM "Template" too, where you use value instead of a property alias (see "Collection views", below).

We’ve already seen how simple it can be to stick a heading into a label, but for properties that aren't as simple as a textbox, we can do that too:

Content pickers

The umbContentName component is the only way to get the name of a picked content item. With a Multinode Treepicker (or a Content Picker allowing multiple items), you'll get a comma-separated list.

Media pickers

Good news! umbContentName handles media too, so no more constructing your own UDIs.

Member pickers

For a member picker, use the umbMemberName component.

The docs suggest umbContentName supports members too, but that rendered nothing for a Member Picker in my testing, so stick to umbMemberName.

Form pickers

Umbraco Forms adds an umbFormName component for its form picker. Without it, {=contactForm} just renders the form's ID.

Form: {umbFormName: contactForm}

URL Picker

The umbLink component will provide the name of a picked link.

If you want something other than the name, the value is an array of link objects, so you can reach into it with an expression, much like we used to in AngularJS.

Other objects

That same trick works for any property editor that stores an object. For example, a colour picker (with labels enabled) stores both the colour and its label.

Rich text editor

The stripHtml filter strips out the HTML markup, leaving just the text. It will also handle the object returned by the rich text editor, otherwise you'd otherwise get [object Object].

Just in case you need the HTML itself, it's in a property called markup:

Too long?

The wordLimit filter limits text to a number of words (${ wordLimit(stripHtml(bodyText), 4) }), and truncate to a number of characters, adding an ellipsis if it had to cut anything:

truncate takes an optional tail to replace the ellipsis, e.g. ${ truncate(stripHtml(bodyText), 35, " (more)") }, or "" for none. Unlike the AngularJS version, there's no "wordwise" option, so it'll happily chop a word in half.

Make it SHOUT

There are also filters for changing case: uppercase, lowercase and titleCase:

Yes/No

Toggles (true/false) give you a boolean in UFM, so an expression can turn it into some text:

The AngularJS-era flipped == 1 still works too. On its own, {=flipped} renders true or false.

Arrays

There's no need for a join filter any more: when the value is an array (tags, checkbox lists, repeatable textstrings, etc.), the umbValue component joins them with a comma for you.

If you'd rather use a different separator, an expression can call the JavaScript join method.

We can also count them, or pick out individual items:

Nesting block lists?

Local block list items from block lists within your block can be accessed by using the alias of the block list property followed by contentData. Getting at the values inside the nested blocks is a bit more involved than in AngularJS. Each block's values are now an array of { alias, value } objects, so we have to find the one we want:

⚠️ This sample will only include the local blocks in v19+.

That's a bit of a mouthful though, which is why I'd recommend writing your own filter for this sort of thing.

To get a count of the items, its best to reference the layout:

What about settings?

Block settings are made available using the $settings property, but only in expressions.

$index

The $index property can be used in block lists and block grids. This is now 0-based, where it used to be 1-based in AngularJS, so you'll probably want to add one.

What's not available

Block labels only get the block's content properties, $settings and $index. So, unlike AngularJS, there's no $contentTypeName (leave the label empty to show the block type's name, or type it out), and no $layout (with the Block Grid's columnSpan and rowSpan).

Regular ol' JS

Expressions support a decent chunk of regular JavaScript: maths, comparisons, &&, ||, ??, the ternary operator, property access and methods on values (like toUpperCase(), split() and replace()).

Unlike AngularJS, arrow functions are allowed! But (as of v17.7) only with brackets around the parameters:

  • ✅ ${ tags.map((t) => t.toUpperCase()) }
  • ❌ ${ tags.map(t => t.toUpperCase()) } renders nothing at all

It's a sandbox though, so there's no access to globals like Math, Date or window, and no template literals.

Fallbacks

An expression can use || to fall back to another value when a field is empty. Each of these previews has a heading, one that's been cleared, and one that's never been set.

If you're using the component syntax, there's a fallback filter instead. But it only works for a field that's been cleared, not one that's never been set, so a new block, or a new property added to an existing block, is still left with a blank label:

We can also fall back to another field, like the rich text when an optional title is missing (truncated, for good measure):

I recommend using || over ?? as emptied fields are an empty string/object rather than null.

Markdown and HTML

Since UFM is Markdown, we are able to use Markdown syntax or HTML as well.

For example:

Or, using HTML:

You can also use Umbraco's own web components, as long as their name starts with umb-, uui- or ufm- (anything else gets stripped out for security). So you can add a tag:

Or an icon (the inline style stops it sitting on a line of its own):

Localisation

The umbLocalize component (or its shorthand, #) renders a backoffice translation in the current user's language.

You can register your own translation keys with a localization extension.

⚠️ This uses the backoffice UI translations, not dictionary items. A dictionary item key just renders the key itself.

Collection views

The templates for custom columns in a collection (what we used to call a "list view") use UFM too. Like in AngularJS, rather than using the property alias, you use value.

Here are a few examples, each with the same three pages:

Property descriptions

This one's new: property descriptions are UFM too! So you can use Markdown (including links) and localisation in them. {umbValue: label} even renders the property's own name, in case you had a need for that!

Writing your own

Much like in AngularJS, you can write your own filters and components. Custom filters work everywhere the built-in ones do, including as functions in expressions.

For an example of each, see my 24 Days in Umbraco article. It was written for an older version of Umbraco, so some details may have changed (for one, filters with arguments now work in expressions).

Troubleshooting

If a label isn't showing what you expect:

  • Blank? An invalid expression (${ heading +* }) renders nothing at all, as does a property alias that doesn't exist. Check your spelling, then your browser's console, where expressions that can't be parsed are logged.
  • [object Object]? The value is an object, like rich text, a colour picker or a link. Use a filter (${ bodyText | stripHtml }), reach into it with an expression (${ colour.label }) or use a specific component ({umbLink: link}).
  • Want to show the syntax itself? To show {=heading} or ${ heading } in a label (or, more likely, a property description), escape it with a backslash (\{=heading}) or wrap it in backticks.
  • Filter not found? You'll see strip-html, title-case and word-limit in older examples. These still work in v17 but are removed in v18, so use the camelCase versions (stripHtml, titleCase, wordLimit).

Further reading