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

Nunjucks: {% setAsync %} to handle Asynchronous Shortcodes nested inside. #2108

Closed
zachleat opened this issue Nov 19, 2021 · 3 comments
Closed

Comments

@zachleat
Copy link
Member

Failing test case:

{% set myVar %}
{% asyncShortcode %}
test content
{% endasyncShortcode %}
{% endset %}

Discovered via #2100 (comment)

Local PR that has some progress on a similar issue: #1749

Nunjucks Related Issues:
mozilla/nunjucks#815
mozilla/nunjucks#1362
mozilla/nunjucks#1363

I tested mozilla/nunjucks#1357 locally and it did not resolve the issue.

Related: macros

Note that the macro docs warn about using async stuff: https://mozilla.github.io/nunjucks/templating.html#macro

Important note: If you are using the asynchronous API, please be aware that you cannot do anything asynchronous inside macros. This is because macros are called like normal functions. In the future we may have a way to call a function asynchronously. If you do this now, the behavior is undefined.

This repo has a setAsync custom tag that I looked into but I don’t think it solved the issue: https://github.com/namshi/nunjucks-setasync

@CodeFoodPixels
Copy link
Contributor

Do you need any more from my PR for this? Happy to do more work on it

@zachleat
Copy link
Member Author

I merged it! It is amazing, thank you @CodeFoodPixels!

@zachleat
Copy link
Member Author

1.0.0-beta.9 will have a new setAsync Nunjucks paired shortcode.

The first argument is a string.

{% setAsync "liquidOutput" %}
{% renderTemplate "md" %}
# Title
{% endrenderTemplate %}
{% endsetAsync %}

@zachleat zachleat added this to the Eleventy 1.0.0 milestone Nov 20, 2021
@zachleat zachleat changed the title Nunjucks: Asynchronous Shortcodes inside of {% set %} Nunjucks: Need a {% setAsync %} to handle Asynchronous Shortcodes nested inside. Nov 20, 2021
@zachleat zachleat changed the title Nunjucks: Need a {% setAsync %} to handle Asynchronous Shortcodes nested inside. Nunjucks: {% setAsync %} to handle Asynchronous Shortcodes nested inside. Jul 27, 2022
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