Long shot this one, but I’ll give it a try. I’m using Hugo to build a snippet / component library. So far this is working great, but one thing that is really bugging me is that partials don’t seem to respect indentitation. This is messing things up for me.
Project structure example
content/blocks/pagetitle.html
content/pages/layouts/example.html
In a page content type I reference the content of a block content type. I’m doing this with a simple shortcode named file.
shortcode - file.html
{{- $code := .Get "code" -}}{{ $site := $.Site }}{{ with site.GetPage ( $code )}}{{ .Content }}{{ end }}
Notice that the latest div is not properly indented. This is ofcourse not a nice experience when you copy this snippet into your project. Is there any approach to fix this behaviour?
This has been proposed and asked often. It’s basically impossible The partial/shortcode does not know what the indention was when it is called. If you KNOW that it’s 4 spaces then put those 4 spaces everywhere in your partial and it might work out well.
The only way I know how you can do that would be a script that runs AFTER hugo and reformats all HTML files in public/.
Maybe something could be done in your specific use case, but not without knowing how shortcodes/file.html looks like. You could add a parameter to the shortcode with an integer that adds some spaces?
There’s a related issue already open, though it’s focused on the highlight shortcode. But the problem regarding the use of a shortcode and indentation is the same.
It’s a looo…oong thread. So here are links to the twosolutions so far.
I have been using that first solution for few years now.