Collapsable Markdown Field in the Craft CP #19424
Answered by
brandonkelly
Aug 12, 2026
Replies: 2 comments 1 reply
|
We have done something similar in an older project via You can either hardcode the help text, output dynamic content by accessing the {# _cp/book_author_guide.twig #}
{% embed '_cp/guide.twig' with {title: 'Book Author Guide', open: true} %}
{% block content %}
{% set bio = element.bio %}
{% if bio|length < 100 %}
<p style="color:red">
The bio you entered is missing or a bit short...
</p>
{% endif %}
<p><a class="go" href="https://example.com" target="_blank">The link</a></p>
{% set guide = craft.entries.section('guide').slug('author-fields').one %}
{% if guide %}
{{ guide.body }}
{% endif %}
{% endblock %}
{% endembed %}The embed: {# _cp/guide.twig #}
<div class="markdown pane">
<details {{ open is defined and open ? 'open' }}>
<summary style="font-weight: bold; font-size:18px; cursor: pointer;">{{ title ?? 'Guide' }}</summary>
<div style="padding-top: 12px;">
{% block content %}{% endblock %}
</div>
</details>
</div> |
0 replies
|
I’ve updated the Markdown field layout element to allow safe HTML, for Craft 6 (#19426). So it will be possible to create that (Unfortunately I couldn’t do it for Craft 5.x, because the Markdown library we’re using won’t parse Markdown nested within HTML elements.) |
1 reply
Answer selected by
brandonkelly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


I’ve updated the Markdown field layout element to allow safe HTML, for Craft 6 (#19426).
So it will be possible to create that
<details>disclosure HTML right within the Markdown element settings, without needing to create a dedicated Twig template for it.(Unfortunately I couldn’t do it for Craft 5.x, because the Markdown library we’re using won’t parse Markdown nested within HTML elements.)