Trying to send email to yesod using hamlet

I am creating a poll site in Yesod (0.10) and I am getting lost in types. Here is a simplified version of 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

      

Another function will call this in the 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 templating tutorial seems to do it. 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.
|]

      

I am getting this type of error.

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

      

I think renderHtml is the wrong function to use, but I can't seem to find what the correct function is. Does anyone know what I am missing? How should I pass a routing function to my Hallelet code?

+3


source to share


3 answers


Quasi-square ( [hamlet|...|]

) returns a function whose argument is also a function. You must first apply this quasi-code 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 extra $

).

PS renderHtml has type Html -> Text

and quasi-square result [hamlet|..|]

has type Render url -> Html

. In the first error message, you noticed that you tried to pass two arguments to renderHtml, and the second error message notes that you did not pass any arguments to the quasi-cable value.

+3


source


Making it easier for the next person looking for it ...

There were two problems. One of them was indicated by the first answer; the village quasi-gatherer itself performs the function. Another problem was that I needed to use the getUrlRenderParams function and not getUrlRender. Final code



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

      

+4


source


Just replace shamlet

instead hamlet

; it doesn't need an argument at all render

.

(As pointed out by joelteon in #yesod.)

+1


source







All Articles