Question

How do I use a type-safe url with setMessage?

I want to change

 ...
 setMessage [shamlet|<span .warning>Warning! See Help.|]
 ...

to a message that contains a link.

From what I could gather thus far, it ought to work somehow like this

 ...
 renderer <- getUrlRender
 let html = [hamlet|<span .warning>Warning! See #
                     <a href=@{HelpR}> Help!|]
 setMessage $ toHtml $ html renderer
 ...

but that code just gives me confusing error messages all over the file.

I did read the printed Yesod Book Chapter on Shakespearian Templates, but I found that it is not very explicit on the involved types. For instance what type does [hamlet|...|]| produce? Without URL-Interpolation, ghci reports t -> Markup but with URL-Interpolation inside, I just get errors.

I am further confused by all the type synonyms involved, e.g. [shamlet|...|] delivers something of type Html, while setMessage expects a Html (). I do not know how to look these up easily: Hoogle often finds nothing on the topic, while Google always finds possibly outdated versions (with examples that no longer work) - sure I get to the newest version eventually, but is there a place where I get an easy overview over these? (Can ghci list all synonyms for a type?)

Note that I actually want to produce the message in a purely functional code fragment, which is later on used by a handler. So that is why I would like to separate the URL rendering from where the hamlet is specified. Thanks for any pointer in the right direction!

Was it helpful?

Solution

I think you want to use getUrlRenderParams. Strangely enough, a related discussion came up on IRC today. Hamlet templates take a URL rendering function as their first argument, and that function must take two parameters: a type-safe URL, and a list of query string parameters. getUrlRender returns a function that doesn't take the query string parameters, which is why you need getUrlRenderParams instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top