[web-devel] [Yesod] Nesting widgets
Michael Snoyman
michael at snoyman.com
Mon Jun 6 21:42:00 CEST 2011
On Mon, Jun 6, 2011 at 8:59 PM, Aren Olson <reacocard at gmail.com> wrote:
> On Mon, Jun 6, 2011 at 12:37, Michael Snoyman <michael at snoyman.com> wrote:
>> Sorry for a terse reply, but the trick is to replace addHamlet with
>> addWidget, and the original code should work. Let me know if you're
>> still having trouble, I should have more time to respond next week.
>
> I'm not sure how addWidget helps with nesting, as it's just 'id'
> internally, right? So what I'd get out of it is still the same Widget
> type as what addHamlet was giving, which doesn't interpolate via ^{}
> as can be demonstrated with this example:
>
> blockW :: Widget () -> Widget ()
> blockW contents = do
> addHamlet [hamlet|
> <div
> ^{contents}|]
Try replacing addHamlet here with addWidget. This has to do with how
polymorphic Hamlet is implemented (again, sorry for the terseness).
> However, if I add an extractBody on contents to pull out the body
> tags, then it works:
>
> blockW :: Widget () -> Widget ()
> blockW contents = do
> body <- extractBody contents
> addHamlet [hamlet|
> <div
> ^{body}|]
>
> It'd certainly make sense to me that using contents directly here
> should work, but it clearly isn't at the moment so I am using
> extractBody to get around that.
>
> -Aren
>
More information about the web-devel
mailing list