[web-devel] on the necessity of extractBody

Michael Snoyman michael at snoyman.com
Wed May 4 07:15:36 CEST 2011


Firstly, polymorphic Hamlet is going the way of the do-do. (Sorry
everyone, the train ride worked out differently than expected, so the
blog post explaining this isn't ready yet.) So going forward these
things should be less of a problem.

I think the reason you're running into trouble is the use of
"addHamlet"; try replacing it with "addWidget" and see what happens.

On Tue, May 3, 2011 at 4:33 PM, Max Cantor <mxcantor at gmail.com> wrote:
> I've heard that its unnecessary, but I can't seem to get out it of my code.  for instance, here is a simple route which should return a small HTML snippet for AJAX requests:
>
>  getAdmPurchDetailRh   :: EncPurchId -> Handler RepHtml
>  getAdmPurchDetailRh epid = withEncPersistKey epid $ \(purchId, purch) -> do
>    -- purchImgData <- runDB $ selectList [] [] 50 offset
>    -- _TODO this will be done FOR EACH Purchase.  need to cache the OcrRefs
>    ocrRefs <- map snd <$> runDB ( selectList [] [] 50 0)
>    mPsiPkv <- runDB (getBy $ PurchImgUnq purchId True)
>    (_, formW, et, nonce) <- runFormPost (purchFormlet purch ocrRefs)
>    let act = AdminRb
>    pc <- widgetToPageContent $ do
>      form <- extractBody formW
>      addHamlet $(Settings.hamletFile "admin/purch-dtl")
>    hamletToRepHtml [$hamlet|\^{pageBody pc}|]
>
> and the hamlet file:
>
> <div>
>  $maybe psiPkv <- mPsiPkv
>    <img src=@{getPurchImgRoute psiPkv}>
>  $nothing
>    <span .missingRecptImage>
>      missing image
>  <form action=@{act} enctype=#{et}>
>    #{nonce}
>    ^{form}
>    <input type=submit>
>
> if I drop the extractBody formW call and replace ^{form} with ^{formW} it fails to compile.
>
> also, is there a way to get rid of the widgetToPageContent call and then extracting it with pageBody pc?  hamletToRepHtml fails when the hamlet references any widgets it seems.
>
> sidenote, i understand that there is alot of polymorphism going on here but I'm still not exactly clear on what i "should" be doing in terms of hamlet, widgets, snippets etc.  any style hints are appreciated.
>
> max
>
>
> _______________________________________________
> 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