【发布时间】:2011-12-11 02:44:34
【问题描述】:
我目前正在通过tutorial on the Yesod Wiki 尝试 Yesod。
首先,我使用 yesod init 创建了一个 yesod 应用程序,并创建了一个 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 定义的小部件中链接静态资源,为什么它在默认布局模板中的行为不同?
【问题讨论】: