I am working a web app based on yesod( without scaffold ). While, with the code become large, it consumes a lot of time when I make a small change in the [whamlet||] and $(hamletFile ..) quasiquoter because my app need to be recompiled.
So I use the Text.Hamlet.Runtime to include my template file at run time. Now, My sample code looks like this:
#ifndef EMBED
render <- getUrlRender
let css1 = render $ StaticR res_css1
css2 = render $ StaticR res_css2
out = render LogoutR
let interp = Map.fromList [("css1", toHamletData css1), ("css2", toHamletData css2), ("LogoutR", toHamletData out)]
tmpl <- renderHamletTemplateFile defaultHamletSettings "tpl/site.hamlet"
page <- renderHamletTemplate tmpl interp
#endif
It seems that the function renderHamletTemplate does not support interpreting url route, so I change my template:
@{StaticR res_css1} to #{css1}
@{StaticR res_css2} to #{css2}
@{LogoutR} to #{LogoutR}
Now, it works for my app, and the #{css1} , #{css2} , #{LogoutR} is interpreted to what i expected in my "tpl/site.hamlet" file.
But, It is a little bit ugly code that I must have a copy of all my template file, just make a little transform to work for me.
How can I just use one template file to work both in compile-time and run-time?
Aucun commentaire:
Enregistrer un commentaire