假设每次刷新页面时我想显示一个随机数。这是我的代码:
...
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文件中应用变量插值?
抱歉英文不好。