Snap Framework:自定义snaplet处理程序将不会呈现模板 [英] Snap Framework: Custom snaplet handler won't render template
问题描述
我刚开始编写自定义的snaplet并遇到了障碍.我有以下基本的snaplet,在"snaplets/admin-pg/snaplets/heist/templates"中有一个角色"模板.有人可以告诉我为什么handleUsers函数不呈现角色"模板吗?我收到未接受处理程序'/pgadmin/users'"错误.我确定我缺少一些非常基本的东西.谢谢.
I'm just getting started with writing custom snaplets and hit a road block. I have the following basic snaplet which has a "roles" template located in the "snaplets/admin-pg/snaplets/heist/templates". Can someone tell me why the handleUsers function does not render the "roles" template? I get a "No handler accepted '/pgadmin/users' " error. I'm sure I'm missing something very basic. Thanks.
我的主应用程序定义如下.它是HasHeist的一个实例
My main app is defined as follows. It is an instance of HasHeist
data App = App
{ _heist :: Snaplet (Heist App)
, _pgadmin :: Snaplet (Admin App)
}
我在主应用程序("Site.hs")中对快照的初始化代码为:
My initializtion code for the snaplet in the main App ("Site.hs") is:
h <- nestSnaplet "" heist $ heistInit "templates"
z <- nestSnaplet "pgadmin" pgadmin $ adminPGInit h
自定义snaplet代码...
Custom snaplet code...
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"
推荐答案
使用addTemplates
代替addTemplatesAt
.您可以从源代码中看到它与您在这里的内容略有不同.
Use addTemplates
instead of addTemplatesAt
. You can see from the source code that it's slightly different from what you have here.
此外,一个不相关的细节,您不需要Admin
数据类型上的类型参数.由于它不使用b,因此不需要它作为类型参数.
Also, an irrelevant detail, you don't need a type parameter on the Admin
data type. Since it does not use b, you don't need it as a type parameter.
这篇关于Snap Framework:自定义snaplet处理程序将不会呈现模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!