Since IO can not be used inside Yesod Template, how can I display a simple current time on a page?
In my .hamlet file, something like:
<h2>
#{show $ getCurrentTime }
getCurrentTime :: IO UTCTime
Since IO can not be used inside Yesod Template, how can I display a simple current time on a page?
In my .hamlet file, something like:
<h2>
#{show $ getCurrentTime }
getCurrentTime :: IO UTCTime
In other words, you need to run the IO action outside of the template.
That outside means the template's handler. So I would write like this.
-- Home.hs
getHomeR = do
time <- liftIO getCurrentTime
defaultLayout $(widgetFile "homepage")
-- homepage.hamlet
<h2>#{show time}