gxtaillon
gxtaillon

Reputation: 1066

Yesod's shakespearean templates (hamlet) and IO

In Hamlet, how does one uses the result of an IO operation inside #{...} ?

For instance :

someIO :: IO String
-----------------

$with stuff <- someIO
    <p>#{stuff}

Fails with

No instance for (blaze-markup-0.6.0.0:Text.Blaze.ToMarkup
                       (IO String))
      arising from a use of `toHtml'

I fear that I have not approached the problem from the right angle, could someone shed some light on this issue for me?

Thank you

Upvotes: 3

Views: 386

Answers (1)

Michael Snoyman
Michael Snoyman

Reputation: 31315

Hamlet is just providing an alternate syntax for normal Haskell code, so like normal Haskell, you have to keep your impure actions separate. In other words, you need to run the IO action outside of the template.

Upvotes: 3

Related Questions