Making two widgets on one page in yesod [closed]
Question
I need to add two widgets together in one page like this :
getPageR :: Handler Html
getPageR = defaultLayout $ do
aDomId <- newIdent
setTitle "Titre de la page"
$(widgetFile "rightzone" ++ "leftzone")
but this gives me a error.
Solution
I don't use yesod, but a quick Hayoo! suggests that the type of widgetFile
is String -> Q Exp
. That's a Template Haskell expression. I'm guessing your error is that you can't apply the ++
operator to a Q Exp
from widgetFile "rightzone"
and a String
from "leftzone"
.
defaultLayout
is WidgetT site IO () -> HandlerT site IO Html
, so $(widgetFile ...)
should be a Template Haskell expression for something of type WidgetT site IO ()
. So, to combine two widgets, you are probably looking for a function with a type like WidgetT site IO () -> WidgetT site IO () -> WidgetT site IO ()
. WidgetT
has a Monad
instance Monad m => Monad (WidgetT site m)
, so Monad
's >>
operator should have the right type to combine two widgets together. If your two widgets are "rightzone" and "leftzone", you probably want to do something like $(widgetFile "rightzone") >> $(widgetFile "leftZone")
. You can probably write this as
getPageR :: Handler Html
getPageR = defaultLayout $ do
aDomId <- newIdent
setTitle "Titre de la page"
$(widgetFile "rightzone") >> $(widgetFile "leftzone")
or as
getPageR :: Handler Html
getPageR = defaultLayout $ do
aDomId <- newIdent
setTitle "Titre de la page"
$(widgetFile "rightzone")
$(widgetFile "leftzone")
I have no idea what >>
means for widgets, but it should have the right type to be able to try it and find out.