dan
dan

Reputation: 45652

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.

Upvotes: 1

Views: 108

Answers (1)

dan
dan

Reputation: 45652

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) 

Upvotes: 1

Related Questions