Skip to content

After precompilation, templates insert extra spacing #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JohnDMathis opened this issue May 3, 2013 · 5 comments
Closed

After precompilation, templates insert extra spacing #508

JohnDMathis opened this issue May 3, 2013 · 5 comments

Comments

@JohnDMathis
Copy link

I have a couple of test templates -- "header" and "body". They contain just a div and some text, and are rendered inside regions labeled "header-region" and "body1-region":

image

That's fine, but when I use the precompiled version of the templates, I see extra spacing inserted, throwing off my layout:
image

@JohnDMathis
Copy link
Author

While this appears to me to be a valid issue, I found a reasonable workaround for some cases: Instead of specifying a div with class "well well-small" as the first line of my template, I used Backbone's view, and specified the class using the className view property. That works in cases where you have a text node as the first child under your div. However, in many cases my templates use an 'h1" or "h2" as the first line. In this case, it still inserts a blank text node, forcing a new line:
image

It looks like it always inserts a blank text line as the first char of a template.

@JohnDMathis
Copy link
Author

I found the issue (sort of) and a true workaround: There is a control character inserted at the head of the template result string. I don't know why, but it's there. For example, in my test case I would expect a string:

<h2>a header</h2>

I would expect the length of this to be 19; 17 chars, plus \r\n. However, the length is actually 20, and the first '<' is at index 1, rather than 0.
I fixed it by adding the following after line 2144, right after the result is obtained from the compiled template:

if(result.indexOf('<')===1)
    result = result.substr(1);

I'll look into forking the code and fixing it properly.

@kpdecker
Copy link
Collaborator

What does your source file look like if you open it in a hex editor? My first guess would be that your editor inserted a byte order mark.

@kpdecker
Copy link
Collaborator

I don't think that we want to start altering the content that is passed to us as there are use cases where control characters that the user might want. Closing as this is something that should be handled on a case by case basis although I'm open to a PR that adds a flag to filter this in the bundled command line app if done as a conditional and in a generic manner.

@rkj1515
Copy link

rkj1515 commented Oct 29, 2014

          <script id="" type="text/x-handlebars-template">
             ....Your template
          </script>

if Script tag is corrupted then also its added a new Line space

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants