尝试使用Hamlet在Yesod中发送电子邮件 [英] Trying to send an email in yesod using hamlet

查看:118
本文介绍了尝试使用Hamlet在Yesod中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Yesod(0.10)中建立一个调查站点,并且迷失了类型. 这是我要做的事情的简化版本.

I am building a survey site in Yesod (0.10) and am getting lost in the types. Here is a simplified version on what I am trying to do.

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

另一个函数将调用此函数,以期希望可以从Network.Mail.Mime中将某些内容传递给simpleMail.上面的函数给出了类型错误:

Another function is going to call this in hopes of getting something that can be passed to simpleMail from Network.Mail.Mime. The above function gives a type error:

Handler/Root.hs:404:13:
    The function `renderHtml' is applied to two arguments,
    but its type `Html -> LT.Text' has only one

这令人困惑,因为模板教程似乎以这种方式进行操作. 但是,如果我修改代码,就像这样...

This is confusing, because the templates tutorial seems to do things this way. But if I modify the code, like this...

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

我收到此类型错误.

Handler/Root.hs:403:24:
    The lambda expression `\ _render[a4TO] -> ...' has one argument,
    but its type `Html' has none
    In the first argument of `renderHtml', namely

我认为renderHtml是使用错误的函数,但是我找不到正确的函数.有人知道我在想什么吗?我应该如何将路由功能传递到我的哈姆雷特代码中?

I think that renderHtml is the wrong function to use, but I can't find what the right function is. Does anyone know what I am missing? How am I supposed to pass the routing function into my hamlet code?

推荐答案

类引用([hamlet|...|])返回其参数为也是的函数.您必须首先应用该准报价值,然后将结果传递给renderHtml:

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:

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

(请注意附加的$).

P.S. renderHtml的类型为Html -> Text,而准引用的结果[hamlet|..|]的类型为Render url -> Html.您看到的第一条错误消息指出您试图将两个参数传递给renderHtml,而第二条错误消息指出您没有将任何参数传递给准报价值.

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.

这篇关于尝试使用Hamlet在Yesod中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆