question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Relative paths for nunjucks imports

See original GitHub issue

I have my nunjucks configure path set to node_modules/@govuk-frontend that way when I import govuk macros I use a path that describes where they are coming from (and they are not confused with my own macros):

{% from 'frontend/components/radios/macro.njk' import govukRadios %}

This has been working fine (for things like the footer), however this doesn’t work when a macro template imports other macros - such as radios.

The fix for this would be to use relative paths for the imports. I have tested locally and it works for me…

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kr8n3rcommented, May 30, 2018

should we also consider having an ‘all.njk’ like we do for JS and SCSS where we import all components?

1reaction
kr8n3rcommented, May 25, 2018

Hi, @web-bert thanks for raising this.

Once the team is back on Tuesday, we’ll have a look to see if this is something we’d want to do and if so how we can work this into our backlog. We’ll keep you posted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolving nunjucks includes using relative paths?
Nunjucks does not allow relative paths. All paths are relative to the configured base directories. Reference. Using relative paths inside an ...
Read more >
Using relative paths inside an include? · Issue #1214 - GitHub
Hi, Is there a way to get the include to understand relative paths that are relative to the file that the include statement...
Read more >
Nunjucks - Eleventy - Netlify
Nunjucks for Eleventy, a simpler static site generator. ... Imports (Relative Path) New in v0.8.4, Relative paths use ./ (template's directory) or ....
Read more >
Layouts and Partials - Acetate
Acetate also allows you to use Nunjucks import in templates. Remember, the path will be relative to your source directory.
Read more >
nunjucks-loader | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found