Hugo: Feature request: Support templating in content files

Created on 11 Oct 2020  路  6Comments  路  Source: gohugoio/hugo

Is there a reason I can't use Go template expressions in content/markdown files?

Proposal

Most helpful comment

I find that having to create one-off shortcodes is significantly less elegant, and more verbose than allowing the use of the template language in content. I'm forced to have some of my content in another file, in a completely different directory. Why not offer the choice to users?

I feel like there's a bit of a parallel with anonymous functions. You don't need them; You can always create a named function. But in practice, the overhead of creating a named function is actually significant. And in this case, essentially, I need to create a named function in another file, which is even more overhead.

And of course, if It's not a one-off use, then named functions/shortcodes are available.

All 6 comments

Because it's Markdown. If you want to add template logic to content files you use Shortcodes.

You can use Inline Shortcodes

@pamubay Thanks, that gets the functionality at least. Though it seems strange that Hugo makes it more inconvenient to access the template language just because you're in a content file, right? Is there any principled reason that there isn't an enableTemplatesInContent param, that lets me use the template language directly, without having to go through the extra work and complexity of defining a shortcode, which may only be used in one place?

@davidsneighbour I mean, it's not really just markdown, right, since shortcodes can be used? Something is already processing the markdown, looking for and evaluating shortcodes.

https://gohugo.io/content-management/shortcodes/#what-a-shortcode-is

Hugo loves Markdown because of its simple content format, but there are times when Markdown falls short. Often, content authors are forced to add raw HTML (e.g., video