我正在使用Yesod进行用户注册过程。该计划是向新注册的用户发送激活其帐户的电子邮件。我试图创建一个小部件,其中包含一个Typed-Url回到接受电子邮件确认码的路由。
--- template.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.
--- User.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类型?
答案 0 :(得分:1)
要解压缩Widget,您需要使用widgetToPageContent。但是,这可能不是你想要的,因为我怀疑你打算在电子邮件中使用CSS和Javascript。相反,您可能希望使用hamletFile
,它只能生成HTML。您需要传入一个URL呈现函数,您可以使用getUrlRenderParams
来获取该函数。咒语将类似于:
renderer <- getUrlRenderer
let html = $(hamletFile "filepath.hamlet") renderer