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

Macro mutates data object in v1.14.0 #692

Open
kachurun opened this issue Dec 12, 2019 · 1 comment
Open

Macro mutates data object in v1.14.0 #692

kachurun opened this issue Dec 12, 2019 · 1 comment

Comments

@kachurun
Copy link

I render templates in browser from strings like this:

const imp = '{% import _self as _macro %}';
const macro = `
	{% macro testMacro(global) %}
		<span>testMacro content</span>
	{% endmacro %}
`;
const template = `
	<div>
		{{ _macro.testMacro(_context) }}

		global.example: {{ global.example ?? 'null' }}
		example: {{ example ?? 'null' }}
                dump: {{ dump(_context) }}
	</div>
`;

const data = {
    example: 'test'
};

Twig.cache();

const tw = Twig.twig({
    id: 'test.html', 
    data: `${ macro }${ imp } ${ template }`
});

tw.renderAsync(data).then((output) => {
    console.log('output', output)
});

And its broken with version 1.14.0. All variables puts in global object ('global' is name of first argument in macro).

I get

        <div>
            <span>testMacro content</span>
            global.example: test
            example: null
            dump: 
            object(2) {
                [_self] => object(1) {
                    [testMacro] => function()
                }
              
                [global]=> object(2) {
                    [example] => string(4) "test"
                    [_macro] => object(1) {
                        [testMacro] => function()
                    }
                }
            }
        </div>

With version 1.13.3 all works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants