Search code examples
haskellheist

How do you update code using loadTemplates for the new Heist API?


This code was working with Heist prior to the 0.10.0 change

main = do
      Right ts <- loadTemplates "templates" $
          bindSplices mySplices defaultHeistState
      etc..

Now I get the error

testdb.hs:59:33: Not in scope: `defaultHeistState'

I know the type signature for loadTemplates has changed to

loadTemplates :: FilePath -> EitherT [String] IO TemplateRepoSource

But I'm having trouble figuring out how to adapt my old code to make it work.


Solution

  • OK I got it to work with this, but I'm open to more elegant ways of doing this

    load baseDir splices = do
        tmap <- runEitherT  $ do
            templates <- loadTemplates baseDir
            let hc = HeistConfig mySplices  [] [] [] templates
            initHeist hc
        either (error . concat) return tmap
    
    main = do
          ts <- load "templates" $ bindSplices mySplices 
          renderWithArgs [("test", T.pack "hello world")]  ts "index" >>= 
            B.putStr . maybe "Page not found" (toByteString . fst)