Haskell 在YesSOD中使用键入的URL生成电子邮件

Haskell 在YesSOD中使用键入的URL生成电子邮件,haskell,widget,yesod,hamlet,Haskell,Widget,Yesod,Hamlet,我正在Yesod进行用户注册过程。计划是向新注册的用户发送一封激活其帐户的电子邮件。我试图创建一个小部件,其中包含一个返回到接收电子邮件确认代码的路由的键入Url ---哈姆雷特 <h3>Email Change Confirmation <p>A new email address has been set for your account with Dropship Center. $case ecrType $of New

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

---哈姆雷特

<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.
电子邮件更改确认
已为您在Dropship Center的帐户设置了新的电子邮件地址。
$case ecrType
元新
请点击
在这里
确认。
---User.hs

import Text.Blaze.Html.Renderer.Text(renderHtml)
postserr::处理程序值
姿势
val返回$object[“错误”..=e]
成功注册{..}->do
…数据库操作。。。
让ecrType=New
代码=(ecrNewConfirm ecr)
html=renderHtml$$(widgetFile“ecr消息”)
…使用“html”作为邮件正文发送确认电子邮件。。。
不幸的是,我一直得到以下错误。我还没弄明白

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>") }
处理程序/用户。hs:84:46: 无法匹配类型“WidgetT site0 m0” 使用“blaze-markup-0.6.0.0:Text.blaze.Internal.MarkupM” 预期类型:blaze-markup-0.6.0.0:Text.blaze.Internal.MarkupM() 实际类型:WidgetT site0 m0() 在调用'asWidgetT'的返回类型中。toWidget' 在“do”块的stmt中: (aswidget.toWidget) ((blaze-markup-0.6.0.0:Text.blaze.Internal.preEscapedText.pack) “电子邮件更改确认\ \ 已为您在Dropship Center的帐户设置了新的电子邮件地址。“) 在“do”块的stmt中: do{(asWidgetT.toWidget) ((blaze-markup-0.6.0.0:Text.blaze.Internal.preEscapedText.pack) “电子邮件更改确认\ \ 已为您在Dropship Center的帐户设置了新的电子邮件地址。“); 案例类型{ 新建->执行{…} 旧->做{…}; (aswidget.toWidget) ((blaze-markup-0.6.0.0:Text.blaze.Internal.preEscapedText.pack) “

”)
是否存在将小部件转换为Html类型的中间阶段?

为了解压缩小部件,您需要使用。然而,这可能不是您想要的,因为我怀疑您是否打算在电子邮件中使用CSS和Javascript。相反,您可能希望使用
hamletFile
,它只生成HTML。您需要传入一个URL呈现函数,您可以使用
getUrlRenderParams
获得该函数。咒语看起来像:

renderer <- getUrlRenderer
let html = $(hamletFile "filepath.hamlet") renderer

renderer是一种“html”类型,一种可以直接传递到blaze Builder“renderHtml”函数中的html?是的。添加额外的字符以平息这种情况。感谢您的帮助,我还遇到了一个问题,在该问题中,hamlet模板无法编译,Url被引用为“@{UserConfirmationR}/#{code}”。我还必须将其替换为这个引用“@{UserConfirmationR code}”。不过,无论如何,这是一种更方便的格式。
renderer <- getUrlRenderer
let html = $(hamletFile "filepath.hamlet") renderer