假设我想在每次刷新页面时显示一个随机数。这是我的代码:
...
import System.Random
...
getHomeR :: Handler Html
getHomeR = do
randomX <- liftIO $ randomRIO (1,999::Int)
defaultLayout $ do
setTitle "Welcome To Yesod!"
$(widgetFile "homepage")
toWidgetBody [hamlet|<div>#{randomX}|]
这很好用。
我使用默认的脚手架站点。现在当我想 #{randomX}
使用homepage.hamlet
<div>#{randomX}
它给了我一个错误
Handler/Home.hs:37:11:
Not in scope: ‘randomX’
Perhaps you meant one of these:
‘randomR’ (imported from System.Random),
‘random’ (imported from System.Random),
‘randoms’ (imported from System.Random)
In the splice: $(widgetFile "homepage")
如何在 hamlet 文件中应用变量插值?
抱歉英语不好。