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

Can't get namespaces to work #733

Closed
ringods opened this issue Mar 16, 2020 · 3 comments
Closed

Can't get namespaces to work #733

ringods opened this issue Mar 16, 2020 · 3 comments

Comments

@ringods
Copy link

ringods commented Mar 16, 2020

In PR pattern-lab/patternlab-node#1135, I'm trying to replace node-twig with this twig library as the engine.

However, I can't seem to get the namespaces feature to work. Here is what I pass to Twig.twig() function:

{
  data: '{% include "@templates/03-article-2col.twig" %}\n',
  allowInlineIncludes: true,
  namespaces: {
    atoms: '/Users/ringods/Projects/personal/patternlab-node/packages/development-edition-engine-twig/source/_patterns/00-atoms/',
    molecules: '/Users/ringods/Projects/personal/patternlab-node/packages/development-edition-engine-twig/source/_patterns/01-molecules/',
    organisms: '/Users/ringods/Projects/personal/patternlab-node/packages/development-edition-engine-twig/source/_patterns/02-organisms/',
    templates: '/Users/ringods/Projects/personal/patternlab-node/packages/development-edition-engine-twig/source/_patterns/03-templates/',
    pages: '/Users/ringods/Projects/personal/patternlab-node/packages/development-edition-engine-twig/source/_patterns/04-pages/',
    macros: '/Users/ringods/Projects/personal/patternlab-node/packages/development-edition-engine-twig/source/_macros/'
  },
  id: 'pages-article'
}

But I get this as result:

Error parsing twig template pages-article: 
TwigException: Unable to find template file @templates/03-article-2col.twig. Error: ENOENT: no such file or directory, stat '@templates/03-article-2col.twig'

In the namespaces configuration, I tried to pass both absolute and relative paths but neither of the two seem to work for me.

@ringods
Copy link
Author

ringods commented Mar 18, 2020

@RobLoach sorry to ping you here directly. I am sort of stuck on this. At first sight, do you have any idea if I am missing something in how I call twig?

@willrowe
Copy link
Collaborator

willrowe commented Aug 1, 2022

Closing since the original PR referenced did not end up using this library. If any one else encounters this issue, please provide a simple, reproducible example of it not working as expected.

@willrowe willrowe closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2022
@lal65
Copy link

lal65 commented Feb 22, 2024

I can reproduce this as well...

Project structure:

_folder
__test.twig
_build.js

test.twig

Hello from twig

build.js

const Twig = require('twig');

const html = Twig.twig({
  data: "{% include '@my-project/test.twig' %}",
  allowInlineIncludes: true,
  namespaces: {
    'my-project': 'folder/',
  }}).render();

console.log(html);

Console output:

lleber@lleber:/var/www/vhost.d/edu/psu/components/packages/static-site$ node build.js 
Error parsing twig template undefined: 
TwigException: Unable to find template file @my-project/test.twig. Error: ENOENT: no such file or directory, stat '@my-project/test.twig'
/var/www/vhost.d/edu/psu/components/node_modules/twig/src/twig.async.js:63
            throw err;
            ^

TypeError: Cannot read property 'valueOf' of undefined
    at /var/www/vhost.d/edu/psu/components/node_modules/twig/src/twig.core.js:1393:35
    at Twig.Thenable.resolvedThen [as then] (/var/www/vhost.d/edu/psu/components/node_modules/twig/src/twig.async.js:130:41)
    at Twig.Template.<anonymous> (/var/www/vhost.d/edu/psu/components/node_modules/twig/src/twig.core.js:1349:18)
    at potentiallyAsyncSlow (/var/www/vhost.d/edu/psu/components/node_modules/twig/src/twig.async.js:47:29)
    at Object.Twig.async.potentiallyAsync (/var/www/vhost.d/edu/psu/components/node_modules/twig/src/twig.async.js:78:16)
    at Twig.Template.render (/var/www/vhost.d/edu/psu/components/node_modules/twig/src/twig.core.js:1345:27)
    at Object.<anonymous> (/var/www/vhost.d/edu/psu/components/packages/static-site/build.js:8:7)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)

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

3 participants