2014-04-04 17 views
0

我正在進行Yesod中的用戶註冊過程。計劃是向新註冊的用戶發送激活其帳戶的電子郵件。我試圖創建一個包含Typed-Url的小部件,返回到接受電子郵件確認碼的路線。使用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 [email protected]{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類型?

回答

1

爲了解壓縮Widget,您需要使用widgetToPageContent。但是,這可能不是你想要的,因爲我懷疑你打算在電子郵件中使用CSS和Javascript。相反,你可能想要使用hamletFile,它只能生成HTML。你需要傳遞一個URL渲染函數,你可以使用getUrlRenderParams。該咒語看起來像這樣:

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

「HTML」的類型是一個Html,可以直接傳遞到其中一個火焰建設者「renderHtml」函數? –

+0

是的。添加額外的字符來安撫SO。 –

+0

感謝您的幫助,我還遇到了一個發佈,其中的哈姆雷特模板將不會編譯與Url引用爲「@ {UserConfirmationR} /#{code}」。我還必須用此參考「@ {UserConfirmationR code}」替換它。不過,無論如何,這是一種更方便的格式。 –

相關問題