Trying to send an email in yesod using hamlet

柔情痞子 提交于 2019-12-06 03:41:06

The quasiquote ([hamlet|...|]) returns a function whose argument is also a function. You must first apply that quasiquote value, and pass the results to renderHtml:

[Edit: as @MattoxBeckman discovered, another issue is the need to use getUrlRenderParams instead of gutUrlRender.]

invitation url = do
  render <- getUrlRenderParams
  return $ renderHtml $ [hamlet|
<p>Dear foo, please take our 
<a href=@{ShowSurveyR url}>survey.
|] render

(Note the additional $).

P.S. renderHtml is of type Html -> Text, while the result of the quasiquote, [hamlet|..|], is of type Render url -> Html. The first error message you saw notes that you tried to pass two arguments to renderHtml, while the second error message notes that you didn't pass any arguments to the quasiquote value.

To make this easier for the next person who goes searching for it...

There were two problems. One was pointed out by the first answer; the hamlet quasiquoter itself takes a function. The other problem was that I needed to use the function getUrlRenderParams, not getUrlRender. The final code is

invitation :: Text -> Handler LT.Text
invitation url = do
   render <- getUrlRenderParams
   return $ renderHtml $ [hamlet|
<p>Dear foo, please take our
   <a href=@{ShowSurveyR url}>survey.
|] render

Just replace shamlet instead of hamlet; it doesn't need a render argument at all.

(As was pointed to me by joelteon at #yesod.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!