
In Yesod, if I have two Widgets, how can I 'nest' the content of one widget inside one of the tags of the other? In effect, I want to be able to do something like widget <- do addHamlet [hamlet| some html |] addCassius [cassius| some css |] otherwidget <- do addHamlet [hamlet|

Hi Aren, You should try including the widget using the ^{} syntax instead of the ${} syntax. See here for an example: http://www.yesodweb.com/show/map/1/183 widget <- do addHamlet [hamlet| some html |] addCassius [cassius| some css |] otherwidget <- do addHamlet [hamlet|
In Yesod, if I have two Widgets, how can I 'nest' the content of one widget inside one of the tags of the other? In effect, I want to be able to do something like
widget <- do addHamlet [hamlet| some html |] addCassius [cassius| some css |] otherwidget <- do addHamlet [hamlet|
and end up with the body contents from widget inside otherwidget's <div> tag, while widget's cassius data still ends up in the page's <head> as normal.
I can't find any documentation or examples of this, and nothing I tried would compile. Is this doable? If so, how?
Thanks, -Aren
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel
-- -barkmadley sent from an internet enabled device

On Mon, Jun 6, 2011 at 00:41, Mark Bradley
You should try including the widget using the ^{} syntax instead of the ${} syntax.
Doesn't appear to work. I tried this: blockW :: Widget () blockW = do contents <- do addHamlet [hamlet|example|] addHamlet [hamlet|

On Mon, Jun 6, 2011 at 12:22, Aren Olson
On Mon, Jun 6, 2011 at 00:41, Mark Bradley
wrote: You should try including the widget using the ^{} syntax instead of the ${} syntax.
Doesn't appear to work. I tried this:
<snip>
Apparently I fail at using Haskell right; obviously contents <- addHamlet won't give me a Widget. :) This code works: blockW :: Widget () blockW = do let contents = addHamlet [hamlet|example|] body <- extractBody contents addHamlet [hamlet|

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.
On Mon, Jun 6, 2011 at 8:34 PM, Aren Olson
On Mon, Jun 6, 2011 at 12:22, Aren Olson
wrote: On Mon, Jun 6, 2011 at 00:41, Mark Bradley
wrote: You should try including the widget using the ^{} syntax instead of the ${} syntax.
Doesn't appear to work. I tried this:
<snip>
Apparently I fail at using Haskell right; obviously contents <- addHamlet won't give me a Widget. :) This code works:
blockW :: Widget () blockW = do let contents = addHamlet [hamlet|example|] body <- extractBody contents addHamlet [hamlet|
Thanks for the help Mark!
-Aren
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel

On Mon, Jun 6, 2011 at 12:37, Michael Snoyman
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|

On Mon, Jun 6, 2011 at 8:59 PM, Aren Olson
On Mon, Jun 6, 2011 at 12:37, Michael Snoyman
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|
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|
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

On Mon, Jun 6, 2011 at 14:42, Michael Snoyman
On Mon, Jun 6, 2011 at 8:59 PM, Aren Olson
wrote: On Mon, Jun 6, 2011 at 12:37, Michael Snoyman
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|
Try replacing addHamlet here with addWidget. This has to do with how polymorphic Hamlet is implemented (again, sorry for the terseness).
Ahah, I follow you now, and yes that does work. Thanks!

On 20:37 Mon 06 Jun , Michael Snoyman 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.
Does that mean that with the basic hamlet package, you can't reuse html? -- Mats Rauhala MasseR

On Mon, Jun 6, 2011 at 11:40 PM, Mats Rauhala
On 20:37 Mon 06 Jun , Michael Snoyman 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.
Does that mean that with the basic hamlet package, you can't reuse html?
I'm not sure what the question means, but to my knowledge there's no problem with HTML reuse. Can you clarify?
-- Mats Rauhala MasseR
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel

On 06:46 Tue 07 Jun , Michael Snoyman wrote:
On Mon, Jun 6, 2011 at 11:40 PM, Mats Rauhala
wrote: On 20:37 Mon 06 Jun , Michael Snoyman 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.
Does that mean that with the basic hamlet package, you can't reuse html?
I'm not sure what the question means, but to my knowledge there's no problem with HTML reuse. Can you clarify?
A while ago I tried to insert hamlet html into another hamlet template, but all of it came out escaped. I figured after your post that it doesn't happen with addWidget, but addWidget is part of the yesod-core package. -- Mats Rauhala MasseR

On Tue, Jun 7, 2011 at 1:57 PM, Mats Rauhala
On 06:46 Tue 07 Jun , Michael Snoyman wrote:
On Mon, Jun 6, 2011 at 11:40 PM, Mats Rauhala
wrote: On 20:37 Mon 06 Jun , Michael Snoyman 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.
Does that mean that with the basic hamlet package, you can't reuse html?
I'm not sure what the question means, but to my knowledge there's no problem with HTML reuse. Can you clarify?
A while ago I tried to insert hamlet html into another hamlet template, but all of it came out escaped. I figured after your post that it doesn't happen with addWidget, but addWidget is part of the yesod-core package.
I'd have to see the code in question to see why it came out escaped, but the short answer is that you can embed HTML without escaping it with pure Hamlet, no Yesod required. Michael

Apparently it was some sort of fail on my part (or old version?), since now that I tested it again, it worked fine. So disregard everything I said earlier :P. head_ = [hamlet| <head> <title>Foo |] page = renderHtml [hamlet| <html> ^{head_} <body> <p>Hello world |] -- Mats Rauhala MasseR
participants (4)
-
Aren Olson
-
Mark Bradley
-
Mats Rauhala
-
Michael Snoyman