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.

Extensionless extends, includes and imports

See original GitHub issue

Is there any way to provide nunjucks with templates files extension name, so we could drop it in extends, includes and imports.

For example, Instead of

{% extends "layout.nj" %}

use

{% extends "layout" %}

I’ve heard that it’s possible to configure extension name when Nunjucks used in conjuration with Express. But what about other use cases, when Nunjucks used on it’s own, or with Grunt?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
rightawaycommented, May 17, 2016

+1 since .njk is now the recommended extension, it would help adoption of it if .njk would be automatically appended where there is no extension provided.

3reactions
ArmorDarkscommented, Apr 27, 2016

@carljm posted in https://github.com/mozilla/nunjucks/pull/691#issuecomment-215252873:

I still don’t like #475 – I think the recommended extension should remain a matter only for the documentation and the community, not something that has an actual effect on the behavior. Even if it were configurable, I still don’t see the benefit – it makes your includes etc correspond less clearly to the actual template files, why is that a good thing?

It’s very minor thing, I agree. But it’s just somehow wrong to ask developer specify extension every single time while importing or including something when you’re clearly working in unified environment.

I think closest example here is ES2016, babel, systemjs. When you’re importing other modules, you do not specify .js extension, unless you really need to specify extension for some serious reason. For example, when importing non-standard for system file. In other words, not .js one, but Sass or CSS. or image. It’s just a good design, since system arguably assumes that you by default would require specific to current environment files only, and not anything else. In some sense, it DRYing out code, by removing constantly repeating and really not useful extension.

Same principle used in many other modern systems.

Option to drop extension just makes Nunjucks more unified with them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extensionless extends, includes and imports · Issue #580 · pallets ...
My proposal is to make file extensions optional in extends, includes and imports. For example, Instead of. {% extends "layout.nj" %}.
Read more >
Typescript eslint - Missing file extension "ts" import/extensions
I have installed eslint-plugin-import & eslint-import-resolver-typescript. And I cannot figure out why, I got that error. node.js · typescript ...
Read more >
Features In-Depth | Less.js
Less extends CSS with dynamic behavior such as variables, mixins, operations and ... such as selector names, property names, URLs and @import statements....
Read more >
import - JavaScript - MDN Web Docs - Mozilla
In Node, extension-less imports often refer to packages in node_modules . Certain bundlers may permit importing files without extensions; ...
Read more >
Spring Boot Reference Documentation
To do so, include the appropriate spring-boot-*.jar files on your classpath. ... To import these extensionless files, you need to give Spring Boot...
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