Snap for Beginners

Sample Chapter: Digestive Functors (Form Processing)

Heist Snaplet

The Heist Snaplet handles the rendering of templates. We will be going over Interpreted Heist in this chapter. There is another usage of Heist called Compiled Heist that is higher performance but also slightly more difficult to work with.

Initializing the Snaplet

As we can see in code/scaffolding, and in the scaffolding chapter, we have to first add Heist to our app definition:

dataApp=App{_heist::Snaplet(HeistApp)}

Then we write a simple instance so we don't have to write with heist in front of all our routes that render templates:

instanceHasHeistAppwhereheistLens=subSnapletheist

Here we declare an instance of HasHeist App, which is to say that we are telling the compiler that our App does indeed have an instance of Heist accessible. We then define heistLens, which is the function that will be called to access heist from our App, to be subSnaplet heist. This is because in our initialization code (as seen in the scaffolding chapter) we define heist to be a subSnaplet of App.

This instance is totally optional, but if we don't write it we will have to prefix the routes that use heist with with heist.

To finish off the initialization, we will go over how we set up heist as a subSnaplet to App: