You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Essentially, in Handlebars 2.0.0, any partial which is indented is now rendered with that indent applied to the beginning of every line output by the partial. So if I have a partial like:
<section>
{{content}}
</section>
and I output it in my post.hbs like:
<body>
{{> my-partial}}
</body>
Then every line of the partial, including every line output by {{content}} will have 4 spaces applied at the beginning, just like the {{> my-partial}} line has.
This sort of makes sense - it makes for nicely aligned source code, but it also fudges with anything in the partial which is whitespace-sensitive, like a <pre> or a <textarea>. Essentially, if you have a nicely formatted code block in your blog content, when it gets rendered to the page, all the lines of code will weirdly have 4 extra spaces at the start.
The solution is simple enough - don't use a partial, or don't indent your partial, but this behaviour is very hard to predict in my opinion.
The discussion on the handlebars repo might lead to a compiler flag we can use to disable this. Alternatively we could downgrade back to handlebars 1.3.0 for rendering themes. If we do neither of these, then we have to be very careful to document this behaviour.
The text was updated successfully, but these errors were encountered:
There is an ongoing discussion about this on the handlebars repo. It was originally discovered as a sort-of-bug-in-Ghost via a weird issue on the forum and applies to themes which use a partial to output content. I'm raising it here as a way to keep track of it.
Essentially, in Handlebars 2.0.0, any partial which is indented is now rendered with that indent applied to the beginning of every line output by the partial. So if I have a partial like:
and I output it in my
post.hbs
like:Then every line of the partial, including every line output by
{{content}}
will have 4 spaces applied at the beginning, just like the{{> my-partial}}
line has.This sort of makes sense - it makes for nicely aligned source code, but it also fudges with anything in the partial which is whitespace-sensitive, like a
<pre>
or a<textarea>
. Essentially, if you have a nicely formatted code block in your blog content, when it gets rendered to the page, all the lines of code will weirdly have 4 extra spaces at the start.The solution is simple enough - don't use a partial, or don't indent your partial, but this behaviour is very hard to predict in my opinion.
The discussion on the handlebars repo might lead to a compiler flag we can use to disable this. Alternatively we could downgrade back to handlebars 1.3.0 for rendering themes. If we do neither of these, then we have to be very careful to document this behaviour.
The text was updated successfully, but these errors were encountered: