Grind’s abstract view system allows for integration of any templating engine. Grind ships with first party support for it‘s own templating engine, Stone, however registering a new engine is straight forward.

Views should be stored in /resources/views.

First, add the grind-view package via your preferred package manager:

yarn add grind-view

Next, you’ll need to add ViewProvider to your app providers in app/Boostrap.js:

import Grind from 'grind-framework'
import { ViewProvider } from 'grind-view'
 
const app = new Grind()
app.providers.push(ViewProvider)

You can send view responses through Express’s res.render():

app.routes.get('/', (req, res) => res.render('welcome'))

This will load /resources/views/welcome.stone, process it through Stone and send it to the browser.

You can pass a second parameter to res.render with an object to pass to the view. The object’s keys are exposed as variables within the view:

app.routes.get('/', (req, res) =>
  res.render('welcome', {
    now: new Date(),
  }),
)

Now in your view you can output {{ now }}.

Views can be precompiled and cached so they’re ready to go in production.

To precompile and cache your views, all you need to do is call view:cache:

yarn cli view:cache

That‘s it! Regardless of what template engine you use, they will know to read cache during boot.

You can quickly clear cache via view:clear:

yarn cli view:clear

Stone is Grind’s default templating engine. For detailed documentation on Stone, check out the Stone docs.

By default, Grind ships with it’s own templating engine, Stone, however you can easily swap it out for another supported engine (or even build your own!).

To change the engine that Grind uses, just update the view.json config file:

{
  "engine": "amazing-new-engine"
}
Edit