Haskell.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview
newer
yesod vs rails 3 asset pipeline

[Yesod] Nesting widgets

older
API change request for WAI

Aren Olson

6 Jun 2011 6 Jun '11
12:05 a.m.

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|

0 0
Reply
Sign in to reply online Use email software

Show replies by date

Mark Bradley

6 Jun 6 Jun
1:41 a.m.

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|

wrote:

...

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

0 0
Reply
Sign in to reply online Use email software

Aren Olson

1:22 p.m.

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: blockW :: Widget () blockW = do contents <- do addHamlet [hamlet|example|] addHamlet [hamlet|

[(Data.Text.Internal.Text, Data.Text.Internal.Text)] -> Data.Text.Internal.Text) -> Html' In the return type of a call of `hamlet-0.8.2:Text.Hamlet.Quasi.toHamletValue' In the first argument of `addHamlet', namely `hamlet-0.8.2:Text.Hamlet.Quasi.toHamletValue (do { (hamlet-0.8.2:Text.Hamlet.Quasi.htmlToHamletMonad . preEscapedString) "<div>"; hamlet-0.8.2:Text.Hamlet.Quasi.fromHamletValue contents; (hamlet-0.8.2:Text.Hamlet.Quasi.htmlToHamletMonad . preEscapedString) "</div>" })' In the expression: addHamlet (hamlet-0.8.2:Text.Hamlet.Quasi.toHamletValue (do { (hamlet-0.8.2:Text.Hamlet.Quasi.htmlToHamletMonad . preEscapedString) "<div>"; hamlet-0.8.2:Text.Hamlet.Quasi.fromHamletValue contents; (hamlet-0.8.2:Text.Hamlet.Quasi.htmlToHamletMonad . preEscapedString) "</div>" }))

0 0
Reply
Sign in to reply online Use email software

Aren Olson

1:34 p.m.

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|

0 0
Reply
Sign in to reply online Use email software

Michael Snoyman

1:37 p.m.

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 wrote:

...

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

0 0
Reply
Sign in to reply online Use email software

Aren Olson

1:59 p.m.

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|

Widget () blockW contents = do body <- extractBody contents addHamlet [hamlet|
0 0
Reply
Sign in to reply online Use email software

Michael Snoyman

3:42 p.m.

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).

...

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

0 0
Reply
Sign in to reply online Use email software

Aren Olson

7 Jun 7 Jun
1:18 a.m.

On Mon, Jun 6, 2011 at 14:42, Michael Snoyman wrote:

...

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!

0 0
Reply
Sign in to reply online Use email software

Mats Rauhala

6 Jun 6 Jun
4:40 p.m.

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

0 0
Reply
attachment
  • attachment.sig
Sign in to reply online Use email software

Michael Snoyman

11:46 p.m.

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?

...

-- Mats Rauhala MasseR

_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel

0 0
Reply
Sign in to reply online Use email software

Mats Rauhala

7 Jun 7 Jun
6:57 a.m.

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

0 0
Reply
attachment
  • attachment.sig
Sign in to reply online Use email software

Michael Snoyman

7 a.m.

On Tue, Jun 7, 2011 at 1:57 PM, Mats Rauhala wrote:

...

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

0 0
Reply
Sign in to reply online Use email software

Mats Rauhala

7:18 a.m.

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

0 0
Reply
attachment
  • attachment.sig
Sign in to reply online Use email software
5096
Age (days ago)
5097
Last active (days ago)

List overview

Download

12 comments
4 participants

Add to favorites Remove from favorites

tags

participants (4)

  • Aren Olson
  • Mark Bradley
  • Mats Rauhala
  • Michael Snoyman

HyperKitty Powered by HyperKitty version 1.3.9.