Indentation control of Partials


I would like to have partials emit their contents at the indentation level at which the {{ partial “foo.html” . }} appears in the outer template.

Is this technically possible?

Would anyone else like to see this behavior?

– Randy


there is another thread about this, and I can’t remember the link, but the idea was, that no, you can’t “easily” do what you want, because the partial just pastes as if standard html. in order to do what you want, you’d have to put the indentation into the partial so it transfers over… or something like that.


Not what you’re asking for, but could you get halfway there with a special partial?

Say you wanted the indentation level to be 12 spaces (or you could pass the number of tabs, I suppose).

{{ partial "pad.html" (slice 12 "foo.html" .) }}

Contents of pad.html:

{{ $output := partial (index $ 1) (index $ 2) }}
{{/* do something to prepend each line of $output with $[0] */}}

Disclaimer: I made this up off the top of my head. It’s probably total nonsense.


That is exactly what I have ended up doing. I am building a large library of partials which could be used in shallow or deeply nested contexts. Just hoping I could have really clean output.


Interesting. I’ll give this a try.


If it works out, post the results here!