Yesod布局中的站点范围变量(django上下文处理器模拟) [英] Sitewide variables in Yesod layout (django context processors analog)
问题描述
我试过做这在Foundation.hs中实例Yesod应用
在 defaultLayout
中的声明:
instance Yesod App其中
...
defaultLayout小部件= do
...
条目< - runDB $ selectList [RubricOnTop ==。 True] []
...
但是这样编译失败:我有一个类型不匹配实体
与 RubricGeneric
。
解决方案
$ forall rubric< - map entityVal rubrics
...
code>
在default-layout-wrapper.hamlet中。
您显示的代码很好,在使用条目
时,需要记住类型是实体专栏
,而不是专栏
。
Is there a possibility to have a sitewide variables in Yesod? Suppose, I have main menu which entries are gathered from DB and that is rendered on every page: should i fetch entries manually in each handler?
I've tried to do this in Foundation.hs in instance Yesod App
declaration in defaultLayout
:
instance Yesod App where
...
defaultLayout widget = do
...
entries <- runDB $ selectList [RubricOnTop ==. True] []
...
But this fails to compile: i have a type mismatch Entity
with RubricGeneric
.
Solution
$forall rubric <- map entityVal rubrics
...
in default-layout-wrapper.hamlet. Haven't found solution to do this in defaultLayout function yet.
The code you've shown is fine, but you'll need to keep in mind when using entries
that the type is Entity Rubric
, not Rubric
.
这篇关于Yesod布局中的站点范围变量(django上下文处理器模拟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!