Templating
The field value is null, or a MarkdownData object:
{{ entry.body.html }} {# the parsed HTML #}
{{ entry.body.raw }} {# the raw Markdown, as typed #}
{{ entry.body.text }} {# parsed, then stripped to plain text #}
{{ entry.body.flavour }} {# the flavour it was parsed with #}
{{ entry.body }} on its own outputs the raw Markdown, so Craft’s own filter still works if you’d rather parse it yourself:
{{ entry.body|md('gfm') }}
{{ entry.body|md(inlineOnly=true) }}
The |marky filter #
For Markdown that isn’t in a Markdown field, whether a plain text field, a plugin setting, or a string you built in the template, |marky parses it the way the field does: reference tags resolved, HTML purified.
{{ entry.summary|marky }}
{{ entry.summary|marky(flavour='original') }}
{{ entry.summary|marky(refs=false, purify=false) }}
Arguments are flavour, refs, purify, purifierConfig and siteId, all optional.
Craft’s |md is untouched and still the right choice when plain Markdown parsing is all you want. The difference is what each one does beyond parsing:
|md |
|marky |
.html |
|
|---|---|---|---|
| Parses Markdown | ✅ | ✅ | ✅ |
| Resolves reference tags | ❌ | ✅ | ✅ |
| Purifies HTML | ❌ | ✅ | ✅ |
| Uses the field’s settings | ❌ | only when piped a field value | ✅ |
Piping a field value, {{ entry.body|marky }}, is the same as {{ entry.body.html }}, since it takes the field’s own settings. It’s worth doing only to override one of them for a single render:
{{ entry.body|marky(refs=false) }}
Empty fields are null, so the usual guard applies:
{% if entry.body %}
{{ entry.body.html }}
{% endif %}