Skip to content
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

Nested if statements causing custom parameters in partials to become repeated/global scope #956

Open
kokuou opened this issue Aug 15, 2018 · 4 comments

Comments

@kokuou
Copy link

kokuou commented Aug 15, 2018

Version: 0.24.3

Error:
Nested if statements cause custom parameters in partials to become global in scope, which causes subsequent uses of that partial to hold onto those parameter values unless they are declared as empty strings or new values. Using gulp.

gulpfile.js

var gulp = require('gulp');
var extname = require('gulp-extname');
var assemble = require('assemble');
var app = assemble();

gulp.task('load', function(cb) {
  app.partials('templates/partials/**/*.hbs');
  app.layouts('templates/layouts/*.hbs');
  app.pages('templates/pages/*.hbs');
  cb();
});

gulp.task('assemble', ['load'], function() {
  return app.toStream('pages')
    .pipe(app.renderFile())
    .pipe(extname())
    .pipe(app.dest('site'));
});

gulp.task('default', ['assemble']);

p.hbs partial

{{#if copy}}{{#if test}}{{test}}{{/if}}<p>{{{copy}}}</p>{{/if}}

index.hbs page file

---
layout: default.hbs
subject: Branded transaction email example
---

{{> p copy="copy1" test="abc" }}
{{> p copy="copy2" }}

{{> p copy="copy3" }}
{{> p copy="copy4" }}

layout.hbs layout file

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
<link href="../src/css/main.css" media="all" rel="stylesheet" type="text/css" />
</head>

<body>

{% body %}

</body>
</html>

expected output

abc
copy1

copy2

copy3

copy4

output produced

abc
copy1

abc
copy2

abc
copy3

abc
copy4
@assemblebot
Copy link

@kokuou Thanks for the issue! If you're reporting a bug, please be sure to include:

  • The version of assemble you are using.
  • Your assemblefile.js (This can be in a gist)
  • The commandline output. (Screenshot or gist is fine)
  • What you expected to happen instead.

If your issue is related to one of the following, please open an issue there:

  • grunt-assemble Issues with using assemble in grunt or the grunt-assemble library.
  • handlebars-helpers Issues with using handlebars helpers from the handlebars-helpers library.

@doowb
Copy link
Member

doowb commented Aug 15, 2018

@kokuou thanks for the issue. I'll try to see if I can figure out what's happening.

FWIW... assemble is being refactored (actually templates which handles the template rendering) and there is better context handling and some other things are changing that may address this issue.

@sompura
Copy link

sompura commented May 23, 2020

Hi,

I am also facing this exact same issue. Is there any fix or workaround?

Thanks,
Rakesh

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

5 participants
@doowb @sompura @kokuou @assemblebot and others