jonschlinkert / handlebars-delimiters

Custom delimiters, for Handlebars templates.
MIT License
41 stars 12 forks source link

Partials are duplicated #2

Open bachly opened 9 years ago

bachly commented 9 years ago

Hi,

Supposedly, I have the express config as below:

handlebars_delimiters(Handlebars, ['{%', '%}']);

Also, I have a template like below

// index.handlebars
{% >htmlHead %}
<body>
    {% >pageLoader %}
</body>
</html>

The issue is: The first partial is rendered correctly. However, when it comes to the second partial, it somehow still caches the first partial and dump out its content, instead of the content of the second partial.

// rendered HTML index page
<html>
   <head>
       <title>Index page</title>
       <style>...</style>
       <script>...</script>
   </head>
<body>
     <head>
         <title>Index page</title>
         <style>...</style>
         <script>...</script>
     </head>
</body>
</html>

My environment is like the below:

// package.json
{
    "express": "^4.7.2",
    "express-handlebars": "^2.0.1",
    "express-session": "^1.11.3",
    "handlebars": "^4.0.2",
    "handlebars-delimiters": "^0.1.0"
}
stefan-wiesner commented 7 years ago

Have a similar issue where always the first value is taken all the time. Looks like its not moving to the next item. It looks more like a var[0] than an caching thing.

@jonschlinkert did you have the time to have a look into that issue?

kmccullough commented 4 years ago

@jonschlinkert I went back to 0.1.2 (https://github.com/jonschlinkert/handlebars-delimiters/commit/9032f0f9ef00bbfe9e87c7c8b5b588070359b38e) and added the following test:

  it('should render correct partials', function() {
    Handlebars.registerPartial('one', 'ONE');
    Handlebars.registerPartial('two', 'TWO');
    useDelims(Handlebars, ['{%', '%}']);
    var actual = Handlebars.compile('{%>one%}{%>two%}')();
    var expectation = 'ONETWO';
    assert.equal(actual, expectation);
  });

The result was AssertionError [ERR_ASSERTION]: 'ONEONE' == 'ONETWO', confirming this issue in that older version.

I returned to master (https://github.com/jonschlinkert/handlebars-delimiters/commit/2a4e3ae2ddca26f950ddd5ecf6824a897d5bcf2c) and added the analogous test:

  it('should render correct partials', function() {
    hbs.registerPartial('one', 'ONE');
    hbs.registerPartial('two', 'TWO');
    delimiters(hbs, ['{%', '%}']);
    var actual = hbs.compile('{%>one%}{%>two%}')();
    var expectation = 'ONETWO';
    assert.equal(actual, expectation);
  });

And the result was ✓ should render correct partials, confirming that this bug has been fixed and may be closed.