Skip to content

Whitespace for standalone partials #297

Closed

Description

@andycnguyen

I have the following template:

<!DOCTYPE html>
<html>
<body>
    {{>Header}}
    This is a test template.
    {{>Footer}}
</body>
</html>

When I compile this template, I'd expect to get this:

<!DOCTYPE html>
<html>
<body>
    This is a header.
    This is a test template.
    This is a footer.
</body>
</html>

Instead, what I get is this:

<!DOCTYPE html>
<html>
<body>
This is a header.    This is a test template.
This is a footer.</body>
</html>

As you can see, the indentations before the first and third lines are gone; and the newlines before the second line and closing body tag are gone. Is this expected, and is there a way to preserve the whitespace just as it is laid out in the base template?

Activity

  1. rexm commented on Apr 27, 2019

    @rexm
    Member

    So there's two different things going on here that I'll summarize first and then explain: 1) what you expect is incorrect; 2) what you are getting is also incorrect, in a different way:

    1. Whitespace (and line breaks) are not significant in HTML, and though Handlebars is technically a general string templating language, the design decisions & opinions it contains are heavily slanted towards using it for an HTML templating language. You should not expect it to preserve implicit line breaks, only explicit line breaks (e.g. if you put \n it will preserve that)
    2. It actually DOES preserve some line breaks when it's not supposed to! That's a bug but one many users are currently relying on, so we'll keep it in 1.x but fix it in v2.

    To get your desired output, put explicit line breaks in your template. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions