I use Yesod on my first site and I have a list of news:
NewsItem date UTCTime default=CURRENT_TIME title String content String author String
which are retrieved in my handler:
newsitems <- runDB $ selectList [] [Desc NewsItemDate]
and is ultimately used in my template:
$if null newsitems <p>No news. $else $forall Entity id entry <- newsitems <article> <h4>#{newsItemDate entry} <p>#{newsItemContent entry}
But I get an error about data types:
Handler/Home.hs:20:11: No instance for (Text.Blaze.ToMarkup time-1.4:Data.Time.Clock.UTC.UTCTime) arising from a use of `toHtml' Possible fix: add an instance declaration for (Text.Blaze.ToMarkup time-1.4:Data.Time.Clock.UTC.UTCTime) In the first argument of `toWidget', namely `toHtml (newsItemDate entry_a6ev)' In a stmt of a 'do' block: toWidget (toHtml (newsItemDate entry_a6ev)) In the expression: do { toWidget ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "<article><h4>"); toWidget (toHtml (newsItemDate entry_a6ev)); toWidget ((Text.Blaze.Internal.preEscapedText . Data.Text.pack) "</h4>\ \<p>"); toWidget (toHtml (newsItemContent entry_a6ev)); .... }
So, I suppose I would like to continue and add to my Import.hs:
import Data.Time (UTCTime) import Data.Time.Format (formatTime) import Text.Blaze (ToMarkup, toMarkup) import Text.Blaze.Internal (string) import System.Locale (defaultTimeLocale) -- format date as 26 July 2012 instance ToMarkup UTCTime where toMarkup a = string (formatTime defaultTimeLocale "%e %B %Y" a)
Which compiles but gives me a runtime error in the browser:
Internal Server Error PersistMarshalError "Expected UTCTime, received PersistText \"2012-08-30\""
So I'm not sure how to solve this, any ideas?
EDIT: Source code for the site in case of need or curiosity: https://github.com/iaefai/socrsite
source share