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

Set blocks prints its content #914

Closed
ArmorDarks opened this issue Nov 15, 2016 · 2 comments · Fixed by #990
Closed

Set blocks prints its content #914

ArmorDarks opened this issue Nov 15, 2016 · 2 comments · Fixed by #990

Comments

@ArmorDarks
Copy link

In 3.0.0 set block for some reason immediately prints it content.

{% set test %}
TEST
{% endset %}

result: {{ test }}

outputs

TEST

result:

As you can see, set print itself immediately, and {{ test }} call doesn't work.

Should it be like that?

@atheros
Copy link

atheros commented Mar 14, 2017

I was trying to use {% set %} as a walkaround the bug #679, so I wouldn't have to use call that breaks variable context. It seems set block doesn't work in macros. As noted above, content is displayed and variable is empty.

At top level, {% set %} block works as expected.

@noahlange
Copy link
Contributor

Temporary workaround: overwrite the compileCapture function in compiler.js with the following.

compileCapture: function(node, frame) {
        // we need to temporarily override the current buffer id as 'output'
        // so the set block writes to the capture output instead of the buffer
        var oldbuf = this.buffer;
        this.buffer = 'output';
        this.emitLine('(function() {');
        this.emitLine('var output = "";');
        this.withScopedSyntax(function () {
            this.compile(node.body, frame);
        });
        this.emitLine('return output;');
        this.emitLine('})()');
        // and of course, revert back to the old buffer id
        this.buffer = oldbuf;
    }

PR incoming.

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

Successfully merging a pull request may close this issue.

3 participants