我目前正在按照Yesod Wiki 上的教程进行 Yesod试验。
首先,我使用创建了一个 yesod 应用程序yesod init
,并创建了一个 Root 处理程序,该处理程序呈现一个名为的小部件文件homepage
:
getRootR = do
mu <- maybeAuth
defaultLayout $ do
h2id <- lift newIdent
setTitle "Home"
addWidget $(widgetFile "homepage")
我在静态目录调用中有一个图像文件static/img/logo.png
触摸后Settings/staticFiles.hs
,我成功地从default-layout.hamlet
通过链接这个文件
<img src=@{StaticR img_logo_png}
现在问题出现了,因为我想在我的homepage
小部件中包含这个静态文件,使用完全相同的代码行。编译时出现以下错误:
Handler/Root.hs:19:21:
Not in scope: `img_logo_png'
In the result of the splice:
$(widgetFile "homepage")
To see what the splice expanded to, use -ddump-splices
In the first argument of `addWidget', namely
`$(widgetFile "homepage")'
In the expression: addWidget ($(widgetFile "homepage"))
所以我的问题是:如何在用 定义的小部件中链接静态资源widgetFile
,为什么它在默认布局模板中的行为不同?