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

3.2.3. Custom Async Tag / CallExtensionAsync not working #1416

Open
BigJk opened this issue Sep 29, 2022 · 2 comments
Open

3.2.3. Custom Async Tag / CallExtensionAsync not working #1416

BigJk opened this issue Sep 29, 2022 · 2 comments

Comments

@BigJk
Copy link

BigJk commented Sep 29, 2022

It seems like this problem came up a few times in the past. I'm using Version 3.2.3. of Nunjucks and I'm trying to use a custom async tag to fetch some content, unfortunately I can't get it to work even with the bare minimum.

Simple Example:

function TestExtension() {
	this.tags = ['test'];

	this.parse = function (parser, nodes, lexer) {
		let tok = parser.nextToken();

		let args = parser.parseSignature(null, true);
		parser.advanceAfterBlockEnd(tok.value);

		let body = parser.parseUntilBlocks('endtest');
		parser.advanceAfterBlockEnd();

		return new nodes.CallExtensionAsync(this, 'run', args, [body]);
	};

	this.run = function (context, arg1, content, callback) {
		setTimeout(100, () => {
			callback(null, nunjucks.runtime.SafeString('Hello world?'));
		});
	};
}

let env = new nunjucks.Environment();
env.addExtension('TestExtension', new TestExtension());

If I use any of my custom tags using CallExtensionAsync the result of renderString is empty. Is there anything I could be doing wrong or is there any chance to get the problem fixed if it's a bug in the codebase?

@ogonkov
Copy link
Contributor

ogonkov commented Oct 4, 2022

It seems like this is a bug in Nunjucks, i have unfinished PR with fix somewhere

@BigJk
Copy link
Author

BigJk commented Oct 4, 2022

Thanks. Using your PR indeed fixes is. Would be nice if this could be merged at some point

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

2 participants