Sitewide variables in Yesod layout (django context

2019-06-26 05:03发布

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.

标签: haskell yesod
1条回答
Lonely孤独者°
2楼-- · 2019-06-26 05:20

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.

查看更多
登录 后发表回答