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

i18n filter not working in liquid templates #12

Open
katrin-krieger opened this issue Mar 9, 2021 · 2 comments
Open

i18n filter not working in liquid templates #12

katrin-krieger opened this issue Mar 9, 2021 · 2 comments

Comments

@katrin-krieger
Copy link

Hi!
First of all, thank you so much for this plugin, great job!
I have encountered an issue, that when I use the i18n filter with liquid templates, eleventy throws an error.

I used the plugin demo code to reproduce the error, so I'm quite sure it's not my project. What I did was that I added {{ 'hello' | i18n }} to the file index.njk located in en-gb/ to test the filter and see if it picks up the translation from i18n/index.js

So what happens is, that if I run eleventy on the plugin demo code, it runs smooth as expected and serves the generated pages.

However, if I save the index.njk as a liquid template index.liquid and explicitly tell eleventy to use liquid as templating engine, I run into the following error:

> Having trouble rendering liquid template ./src/en-gb/index.liquid

`TemplateContentRenderError` was thrown
> Cannot read property 'page' of undefined, file:./src/en-gb/index.liquid, line:3

`RenderError` was thrown
> Cannot read property 'page' of undefined

`TypeError` was thrown:
    TypeError: Cannot read property 'page' of undefined
        at /home/kati/git/eleventy-plugin-i18n-demo-master/node_modules/eleventy-plugin-i18n/.eleventy.js:16:40
        at /home/kati/git/eleventy-plugin-i18n-demo-master/node_modules/@11ty/eleventy/src/BenchmarkGroup.js:30:26
        at Object.render (/home/kati/git/eleventy-plugin-i18n-demo-master/node_modules/liquidjs/dist/liquid.common.js:1914:26)
        at /home/kati/git/eleventy-plugin-i18n-demo-master/node_modules/liquidjs/dist/liquid.common.js:1807:21
        at Array.reduce (<anonymous>)
        at Object.evalValue$$1 [as evalValue] (/home/kati/git/eleventy-plugin-i18n-demo-master/node_modules/liquidjs/dist/liquid.common.js:1806:29)
        at Object._callee4$ (/home/kati/git/eleventy-plugin-i18n-demo-master/node_modules/liquidjs/dist/liquid.common.js:1786:30)
        at tryCatch (/home/kati/git/eleventy-plugin-i18n-demo-master/node_modules/liquidjs/dist/liquid.common.js:108:40)
        at Generator.invoke [as _invoke] (/home/kati/git/eleventy-plugin-i18n-demo-master/node_modules/liquidjs/dist/liquid.common.js:319:22)
        at Generator.prototype.<computed> [as next] (/home/kati/git/eleventy-plugin-i18n-demo-master/node_modules/liquidjs/dist/liquid.common.js:156:21)
Wrote 0 files in 0.09 seconds (v0.11.1)

I didn't change anything else, just renaming the index.njk to index.liquid and putting liquid instead of njk as value for markdownTemplateEngine in .eleventy.js

My eleventy version is 0.11.1, the plugin version is 0.1.0

What am I missing here?

Cheers
Katrin

@adamduncan
Copy link
Owner

adamduncan commented Mar 18, 2021

Hey @katrin-krieger, thanks for the feedback and error report. I was able to reproduce this locally using liquid.

I'll have to do some digging and work out why the page context might different between templating languages.

Something in this ballpark being available in njk but not liquid 🤔

@adamduncan
Copy link
Owner

I did a little more digging on this. Seems the use of this in filters is possible in Nunjucks, but untested in other templating languages.

Related: #1047, #741, #1591

We might have to revisit this assumption when v1.0.0 transforms are released

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