[web-devel] [yesod] how convert Content to String or Text
michael at snoyman.com
Wed Jul 6 22:02:31 CEST 2011
On Wed, Jul 6, 2011 at 12:18 PM, Dmitriy Nikitinskiy <nick at bel.ru> wrote:
> Hello All.
> I have following code:
> getMyRoute :: String -> Handler RepXml
> getMyRoute r = liftM RepXml $ hamletToContent [hamlet|<node |]
> getOtherRoute :: Handler ()
> getOtherRoute = do
> (RepXml mycontent) <- getMyRoute "something"
> -- how write mycontent to file here?
> -- let str = ???? or str <- ????
> -- liftIO $ writeFile "myfile.xml" str
> return ()
> How convert Yesod.Content.Content to String or Text?
I would try to convert the Content. Instead, I'd write a helper function:
myXml :: String -> Hamlet MyRoute
myXml r = [hamlet|<node|]
Then you could use myXml from both getMyRotue and getOtherRoute. In
order to render a Hamlet, you'll need to get a URL rendering
function. So getOtherRoute would look something like:
getOtherRoute = do
renderUrl <- getUrlRenderParams
let lbs = renderHamlet renderUrl $ myXml "something"
liftIO $ Data.ByteString.Lazy.writeFile "myfile.xml" lbs
 It's a function that converts a type-safe URL into a String.
More information about the web-devel