assemble / assemble

Get the rocks out of your socks! Assemble makes you fast at web development! Used by thousands of projects for rapid prototyping, themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websites/static site generator, an alternative to Jekyll for gh-pages and more! Gulp- and grunt-friendly.
http://assemble.io/
MIT License
4.24k stars 278 forks source link

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

Open kokuou opened 6 years ago

kokuou commented 6 years ago

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 commented 6 years ago

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

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

doowb commented 6 years ago

@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 commented 4 years ago

Hi,

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

Thanks, Rakesh