[web-devel] [ Yesod ][ Newbie ][ Widgets ] Ways of adding app manu
Michael Snoyman
michael at snoyman.com
Fri Jul 8 13:55:48 CEST 2011
The problem is that admin-layout.hamlet embeds a Widget inside of it,
making admin-layout.hamlet itself a Widget. However, you are using
hamletToRepHtml, which expects a Hamlet. That's the type error. The
final unwrapping of a Widget and conversion to a Hamlet *is* a bit
tricky; the best place for an example of how to do it right is from
the scaffolded site, in the implementation of defaultLayout.
HTH,
Michael
On Fri, Jul 1, 2011 at 4:43 PM, Kamil Ciemniewski
<ciemniewski.kamil at gmail.com> wrote:
> Hi all,
>
> I'm trying to add to my "admin layout" main menu in Yesod.
>
> Normally - doing it in Rails - I would create a partial
> or helper and then use it in my layout file.
>
> But here in Yesod - the concept of widgets seems
> somewhat fereign to me. I don't quite get them.
>
> In my Handler.Admin module I define:
>
> adminLayout :: GWidget MyApp MyApp () -> GHandler MyApp MyApp RepHtml
> adminLayout widget = do
> mmsg <- getMessage
> mroute <- getCurrentRoute
> pc <- widgetToPageContent $ do
> widget
> hamletToRepHtml $(hamletFile "admin/admin-layout")
>
> then I define my widget ( all in the same file ):
>
> mainMenu :: Widget ()
> mainMenu =
> addWidget $(widgetFile "admin/_menu")
>
> And finally in "admin/admin-layout.hamlet" I'm trying to render my menu:
>
> ...
> ^{mainMenu}
> ...
>
> All without a luck.. Compiler yells at me strange ( to me ) things:
>
> Handler/Admin.hs:31:27:
> Couldn't match expected type `GGWidget
> MyApp (GHandler MyApp MyApp) ()'
> with actual type `(url0 -> [(T.Text, T.Text)] -> T.Text)
> ->
> blaze-html-0.4.1.1:Text.Blaze.Internal.Html'
> Expected type: Widget ()
> Actual type: hamlet-0.8.1:Text.Hamlet.Quasi.Hamlet url0
> In the return type of a call of `pageBody'
> In the first argument of
> `hamlet-0.8.1:Text.Hamlet.Quasi.fromHamletValue', namely
> `pageBody pc'
>
> Which doesn't occur when I'm not trying to render "mainMenu" widget.
>
> What am I doing wrong? And are there any informations about using widgets
> anywhere?
> ( because I haven't found many.. )?
>
> Best regards
> Kamil Ciemniewski
>
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
>
More information about the web-devel
mailing list