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

{% include %} tags do not accept arbitrary expressions #115

Open
wardourdigital opened this issue May 23, 2021 · 8 comments
Open

{% include %} tags do not accept arbitrary expressions #115

wardourdigital opened this issue May 23, 2021 · 8 comments
Labels
bug Something isn't working pinned Go away stale bot

Comments

@wardourdigital
Copy link

wardourdigital commented May 23, 2021

Environment
Node version: v14.16.0
simple-nunjucks-loader version: 3.1.0
webpack version: 5.37.1

Webpack

{
    test: /\.njk|html$/,
    use: [{
        loader: "simple-nunjucks-loader",
        options: {
            searchPaths: ["src-local-nunjucks/templates", "src-hubspot-theme/modules"],
            filters: {
                filter: path.join(__dirname, "filter.js"),
            },
        },
    }, ],
},

Describe the bug
According to the documentation of nunjucks:

include actually accepts any arbitrary expression, so you can pass anything into it, as long as the expression evaluates to a string or a compiled Template object: {% include name + ".html" %}.
Include

When I attempted to do this:

{% macro getBlock(name) %}
    {% include name + '-module/module.html' %}
{% endmacro %}

{{ getBlock("card-section") }}

I get the error:

ERROR in Error: Child compilation failed:
  Module build failed (from ./node_modules/simple-nunjucks-loader/lib/cjs/loader  .js):
  TypeError: Cannot read property 'split' of undefined

Expected behavior
For the named template to be included into the page.

@wardourdigital wardourdigital added the bug Something isn't working label May 23, 2021
@ogonkov ogonkov added the pinned Go away stale bot label May 24, 2021
@ogonkov
Copy link
Owner

ogonkov commented May 25, 2021

Thank you for your report, will look at this issue on the weekend.

@ogonkov
Copy link
Owner

ogonkov commented Jul 27, 2021

I have add warnings for such imports. Full support is on the way.

@jakefentress
Copy link

This would be a huge help to have supported. Any news or tips for workarounds?

@ogonkov
Copy link
Owner

ogonkov commented Feb 2, 2022

I have started to refactor imports/assets in #121 to use same flow for both to load dynamic assets (imports with variables), but it's still WIP.

@jakefentress
Copy link

A little bump here. Is this still under development?

@ogonkov
Copy link
Owner

ogonkov commented Sep 7, 2022

Yes, it still priority. Loader code is a bit of mess. I planned to convert it to TS first, to have more control over all the abstractions.

@ArmandoAmador
Copy link

ArmandoAmador commented Jan 23, 2023

@wardourdigital @jacobfentress

Did anyone figure out a solution for this?

I'm also having the same issue when including a named template inside a Macro.

ModuleBuildError: Module build failed (from ./node_modules/simple-nunjucks-loader/lib/cjs/loader.js):
TypeError: Cannot read property 'split' of undefined

@ogonkov
Copy link
Owner

ogonkov commented Jan 24, 2023

Hello, still on it. Sorry for delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pinned Go away stale bot
Projects
None yet
Development

No branches or pull requests

4 participants