simon-dt/gulp-twig

‘set’ variable causes a bug

Closed this issue · 7 comments

icai commented

{% set bodyCls = 'sss' %}

If have a template set this, all template render the ClassName while all template extends the same layout

olets commented

I don't completely understand. Can you post example code, or make a https://twigfiddle.com/ to demo the problem?

icai commented

@olets If have a template set this, all template render the same ClassName while all template extends the same layout, I also the option.extend (Twig.extend ) to rewite the Twig.token.definitions

icai commented

@example

index.page


{% extends 'layout.html' %}

{% set bodyCls = 'fixed-sidebar full-height-layout gray-bg skin-1' %}

{% block style %}
{% endblock %}

{% block body %}
{% endblock %}

other.page

i never set the bodyCls, but this page also have the bodyCls like the index.page

{% extends 'layout.html' %}

{% block style %}
{% endblock %}

{% block body %}
{% endblock %}
icai commented

@olets
here is the task code

var twig = require('gulp-twig');
return gulp.src(['./views/**/*.html', '!./views/error.html', '!./views/layout.html'])
    .pipe(twig({
        extend: function(Twig) {
            require('./config/twig')(Twig);
            // twigConfig(Twig);
        },
        base: './views/',
        data: {
            // title: 'Express'
        }
    }))
    .pipe(gulp.dest(opt.tmp));
olets commented

Don't know what your layout.twig is like, so guessing a little here. Are you saying this?

For

{# no-x.twig #}

{% extends '_extended.twig' %}
{# x.twig #}

{% extends '_extended.twig' %}
{% set x = 1 %}
{# _extended.twig #}
{{ x }} {# or `x is defined ? x` if strict variables is turned on #}

x.twig and no-x.twig compile to

1

?


I tried that with the latest gulp-twig, and @@no-x.twig compiled to an empty file.

@icai can you make a minimal example that reproduces your problem? I wonder if the problem might be something in yourlayout.html or your ./config/twig

olets commented

Are you saying #44 replaces this issue? If so, go ahead and close this one