Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为了可重用性,我想在另一个小部件中重用。例如,小部件文件blogpost.hamlet可以包含帖子的显示方式,并且blog.hamlet可以包含完整的博客。
blogpost.hamlet
blog.hamlet
以下内容blog.hamlet不起作用:
$forall post <- posts ^{widgetFile "blogpost")
那么,将一个小部件嵌入另一个小部件的正确语法是什么?
Hamlet 语法不支持在其中嵌入 Template Haskell 拼接,这使得您正在寻找的代码无法实现。相反,您需要在 Haskell 中创建一个辅助函数,例如:
blogpost post = $(widgetFile "blogpost")
然后在 blog.hamlet 中,您可以拥有:
$forall post <- posts ^{blogpost post}