我剛剛開始編寫自定義snaplets並命中路障。我有以下基本snaplet,它具有位於「snaplets/admin-pg/snaplets/heist/templates」中的「角色」模板。有人能告訴我爲什麼handleUsers函數不呈現「角色」模板?我收到「沒有處理程序接受」/ pgadmin/users'「錯誤。我相信我錯過了一些非常基本的東西。謝謝。捕捉框架:自定義的snaplet處理程序不會呈現模板
我的主應用程序定義如下。這是HasHeist的實例
data App = App
{ _heist :: Snaplet (Heist App)
, _pgadmin :: Snaplet (Admin App)
}
我在主應用程序( 「Site.hs」)的snaplet initializtion代碼:
h <- nestSnaplet "" heist $ heistInit "templates"
z <- nestSnaplet "pgadmin" pgadmin $ adminPGInit h
定製snaplet代碼...
data Admin b = Admin { name :: String}
adminPGInit :: HasHeist a => Snaplet (Heist a) -> SnapletInit a (Admin a)
adminPGInit h = makeSnaplet "admin-pg" description datadir $ do
config <- getSnapletUserConfig
fp <- getSnapletFilePath
addTemplatesAt h "" fp
addRoutes [ ("/users", handleUsers)
, ("/foo", handleFoo)]
return $ Admin "Admin Snaplet"
where
description = "PostgreSQL Admin"
datadir = Just $ liftM (++"/resources") getDataDir
handleUsers :: HasHeist b => Handler b (Admin b)()
handleUsers = do
render "roles"
handleFoo :: HasHeist b => Handler b (Admin b)()
handleFoo = writeBS "foo from admin"
這樣做。謝謝! – 2013-05-12 18:27:28