Syntax variables in Yesod layout (django analog processors)

Is it possible to have sitewide variables in Yesod? Suppose I have a main menu, which records are collected from the database and which are displayed on each page: do I need to manually extract records in each handler?

I tried to do this in Foundation.hs in the instance Yesod App defaultLayout in defaultLayout :

  instance Yesod App where ... defaultLayout widget = do ... entries <- runDB $ selectList [RubricOnTop ==. True] [] ... 

But this does not compile: I have an Entity type mismatch with RubricGeneric .

Decision

  $forall rubric <- map entityVal rubrics ... 

in default-layout-wrapper.hamlet. Could not find a solution for this in the defaultLayout function.

+4
source share
1 answer

The code you showed is great, but when using entries you need to keep in mind that the type is Entity Rubric , not Rubric .

+3
source

All Articles