handlebars.java icon indicating copy to clipboard operation
handlebars.java copied to clipboard

Indentation When Partial Expands to Template Variable

Open gchallen opened this issue 6 years ago • 1 comments

I need to be able to template content while preserving indentation across multiple lines. (We use templating to insert student code submission into a wrapper, so indentation is important to preserve for legibility and linting.)

The following approach (taken from StackOverflow) works with handlebars.js:

  • Register a partial that expands to {{{ contents }}}. Call it Content.
  • Then use {{>Content }} in lieu of {{{ contents }}} in the input.

However, the same approach in handlebars.java does not work. Indentation is only preserved on the first line, both with and without prettyprint(true).

I don't know if the handlebars.js behavior conforms to the spec or not. Regardless, it would be nice to support this use case somehow. (Currently I'm adding the indentation to the input source manually, but this is brittle in the general case.)

gchallen avatar Jul 12 '19 14:07 gchallen

@gchallen I ran into this issue too and wrote about it in https://github.com/jknack/handlebars.java/issues/401

spacether avatar Oct 17 '21 19:10 spacether