npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

adonis-nunjucks

v1.0.2

Published

Nunjucks templating ViewProvider provider for AdonisJs

Downloads

14

Readme

Adonis Nunjucks

Nunjucks templating provider for AdonisJs framework version 4.

Installation

In order to use adonis-nunjucks

npm install adonis-nunjucks --save

Once you have installed the provider from npm, make sure that the ViewProvider is registered as a provider inside start/app.js file.

const providers = [
  'adonis-nunjucks/providers/ViewProvider'
]

Make sure the default edge provider (@adonisjs/framework/providers/ViewProvider) is not registered as they will conflict with each other.

Compatibility

This package has been rebuilt for Adonis 4 and is incompatible with Adonis 3 and earlier. For Adonis v3 install the previous version (3.01) with :

npm install adonis-nunjucks --save

Basic Usage

Let’s start with the basic example of saying Hello world by rendering a nunjucks template. All of the views are stored inside resources/views directory and end with .html extension.

Create a nunjucks template at resources/views/hello.html. You can use an adonis/ace command to create the view.

adonis make:nunjucks home

    ✔ create  resources/views/home.html

Now let's create a route that renders it:

Route.get('/', ({ view }) => {
  return view.render('home')
})

The view.render method takes the relative path to the view file. There is no need to type .html extension.

View Methods

These methods are available on the view context object in controllers and middleware.

view.share(locals)

Share variables as a local with this template context.

| Param | Type | Description | | --- | --- | --- | | locals | Object | Key value pairs |

Example

Quite often you want to share request specific values with your views, this can be done in middleware or controllers by passing an object to the share method.

class SomeMiddleware {
  async handle ({ view }, next) {
    view.share({
      apiVersion: request.input('version')
    })

    await next()
  }
}

Inside your views, you can access it like any other variable

{{apiVersion}}

view.render(template, locals) ⇒ String

Render a nunjucks template

Returns: String - HTML rendered output

| Param | Type | Description | | --- | --- | --- | | template | String | View file (.html extension not required) | | locals | Object | Variables to be passed to the view |

view.renderString(string, locals) ⇒ String

Render a string of nunjucks

Returns: String - HTML rendered output

| Param | Type | Description | | --- | --- | --- | | string | String | String to be rendered | | locals | Object | Variables to be passed to the view |

View Helpers

A number of global methods and contextual helpers are injected into all views.

Request

All views have access to the current request object, and you can call request methods inside your templates as well.

The request URL is {% request.url() %}

Also, there is a direct helper to get the URL.

The request URL is {% url %}

More documentation coming soon.

License

FOSSA Status