Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding OnLoad hooks for Heist templates using the Snap Web Framework

I wish to add some hooks for pre-processing Heist templates in a web application using Snap. My naïve approach so far has been to use the following code in my application initializer:

app :: SnapletInit App App
app = makeSnaplet "app" "The main web application" Nothing $ do
    -- ...
    h <- nestSnaplet "heist" heist $ heistInit "resources/templates"
    -- ...
    modifyHeistTS . addOnLoadHook $ myTemplateHook

This code does of course not work, since the hook is added after the templates are loaded from "resources/templates"

How would one go about modifying the Heist template state before the initial templates are loaded, in order to add OnLoad hooks?

like image 493
dflemstr Avatar asked Apr 09 '26 09:04

dflemstr


1 Answers

Excellent question. It looks like this is an oversight on my part when designing the library. I'll think about how best to support this and get back to you.

If you want an immediate workaround, insert something to add your hook to the template state that gets passed into loadTemplates here. Or alternatively, you could modify emptyTemplateState directly in Heist.

Update: I added a heistInit' function that should take care of this issue. It'll be in the next hackage release. Until then, you can get it from github.

like image 53
mightybyte Avatar answered Apr 11 '26 08:04

mightybyte



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!