0

我正在 Yesod 进行用户注册过程。该计划是向新注册的用户发送一封电子邮件,以激活他们的帐户。我试图创建一个小部件,其中包含一个返回到接受电子邮件确认代码的路由的 Typed-Url。

---模板.hamlet

<h3>Email Change Confirmation
<p>A new email address has been set for your account with Dropship Center.
    $case ecrType
        $of New
            <p>Please click
            <a href=@{UserConfirmationR}/#{code}>here
            to confirm.

---用户.hs

import           Text.Blaze.Html.Renderer.Text (renderHtml)

postUserR :: Handler Value
postUserR = do
    val <- parseJsonBody :: Handler (Result Registration)
    case val of
        Error e -> return $ object [ "error" .= e ]
        Success Registration{..} -> do

        ...database actions...

        let ecrType = New
            code    = (ecrNewConfirm ecr)
            html    = renderHtml $ $(widgetFile "ecr-message")

        ...send confirmation email using "html" as the message body...

不幸的是,我不断收到以下错误。我一直无法弄清楚。

Handler/User.hs:84:46:
Couldn't match type `WidgetT site0 m0'
              with `blaze-markup-0.6.0.0:Text.Blaze.Internal.MarkupM'
Expected type: blaze-markup-0.6.0.0:Text.Blaze.Internal.MarkupM ()
  Actual type: WidgetT site0 m0 ()
In the return type of a call of `asWidgetT . toWidget'
In a stmt of a 'do' block:
  (asWidgetT . toWidget)
    ((blaze-markup-0.6.0.0:Text.Blaze.Internal.preEscapedText . pack)
       "<h3>Email Change Confirmation</h3>\
       \<p>A new email address has been set for your account with Dropship Center.")
In a stmt of a 'do' block:
  do { (asWidgetT . toWidget)
         ((blaze-markup-0.6.0.0:Text.Blaze.Internal.preEscapedText . pack)
            "<h3>Email Change Confirmation</h3>\
            \<p>A new email address has been set for your account with Dropship Center.");
       case ecrType of {
         New -> do { ... }
         Old -> do { ... } };
       (asWidgetT . toWidget)
         ((blaze-markup-0.6.0.0:Text.Blaze.Internal.preEscapedText . pack)
            "</p>") }

是否有一些将 Widget 转换为 Html 类型的中间阶段?

4

1 回答 1

1

为了解压一个 Widget,你需要使用widgetToPageContent。但是,这可能不是您想要的,因为我怀疑您是否打算在电子邮件中包含 CSS 和 Javascript。相反,您可能想要使用hamletFile,它可以只生成 HTML。您需要传入一个 URL 呈现函数,您可以使用getUrlRenderParams. 咒语看起来像:

renderer <- getUrlRenderer
let html = $(hamletFile "filepath.hamlet") renderer
于 2014-04-06T05:43:05.540 回答