Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

shortcode does not get rendered in markdown fields except for page content?

Started by Anna 3 weeks ago · 4 replies · 438 views
3 weeks ago

I’m unsure if this is maybe a bug, or if I’m missing something. When I put [div]something[/div] into the page content of the site I’m working on, it gets rendered as a div. If I put that into any other markdown field I’ve defined myself, it gets output as-is. Do I need to allow or activate shortcode rendering somewhere, maybe?

3 weeks ago

@Netzhexe, you need to add |markdown|shortcodes|raw twig filters, or just |shortcodes|raw if you only need to convert shortcodes. UPD: Here is a link to the docs.

last edited 08/06/26 by Vadym
3 weeks ago

Thank you Vadym! My problem persists, and while I still think I might be doing something wrong, I’m starting to get suspicious. Please bear in mind that this problem only occurs in blueprint-defined fields, in the regular page content things work differently.

I found one thing in the docs under troubleshooting that sounds relevant: “Ensure include_default_shortcodes: true”. However, that setting seems to be nowhere? I tried just putting it in the config file for Shortcode Core (and Shortcode UI for good measure), but no dice. I also tried different parsers, to no avail.

My output with various filters is as follows:

{{ page.header.contact_info|markdown }} results in unprocessed shortcodes:

image.png

{{ page.header.contact_info|shortcodes|markdown }} results in processed shortcodes with markdown in between:

image.png

{{ page.header.contact_info|raw }} gives me no processing whatsoever:

image.png

{{ page.header.contact_info|markdown|shortcodes }} results in processed shortcodes and everything in html:

image.png

—Oh, and fascinatingly! {{ page.header.contact_info|markdown|shortcodes|raw }} gives me beautiful output as expected! (I only just thought to try that.) But is that really the way to do it? 🤔

3 weeks ago

—Oh, and fascinatingly! {{ page.header.contact_info|markdown|shortcodes|raw }} gives me beautiful output as expected! (I only just thought to try that.) But is that really the way to do it?

Isn't that exactly what Vadym has suggested in his first reply?

By the way... Why are you adding shortcodes to wrap the data in a div and markdown for styling to the header of a page?

I don't think it is the task of a content writer to define the styling and layout of data. That's the task of Twig by using for example an address partial.

I think I would use Twig only, to wrap the address within a <div> and use <h2> and <h3> in Twig to format the parts of the address.

Am I missing something?

last edited 08/08/26 by pamtbaau
2 weeks ago

By the way... Why are you adding shortcodes to wrap the data in a div and markdown for styling to the header of a page?

I don't think it is the task of a content writer to define the styling and layout of data. That's the task of Twig by using for example an address partial.

I quite agree on that. It’s a case of someone else doing the design and some content bits only becoming clear later (varying number of addresses), and since it is super unlikely that the client is going to change these bits in the next years some shortcode div partitioning seemed to me the most pragmatic solution. I may yet do it properly, we’ll see.

I think I was just confused about the behaviour because regular page content with shortcodes does not require being run through three twig filters to show up as rendered html… 🤔

But frankly, I was heavily focusing on this project to finish it before going on holiday, and now the client apparently is happy to wait until September, so I am going to put it all out of my mind for now and get back to it then.

Many thanks and peace to you all!

Suggested topics

Topic Participants Replies Views Activity
Support · by cvgrenoble, 1 day ago
3 50 20 hours ago
Support · by Paul Hodges, 1 month ago
19 514 1 week ago
Support · by Lauw, 1 week ago
2 126 1 week ago
Support · by gtx, 4 weeks ago
4 390 3 weeks ago
Support · by Anna, 1 month ago
9 495 4 weeks ago