问题描述
出于可重用性,我想在另一个内部重用一个小部件.例如,小部件文件blogpost.hamlet
可以包含帖子的显示方式,而blog.hamlet
可以包含完整的博客.
For reusability, I want to re-use a widget inside another. For instance, the widget file blogpost.hamlet
could contain how a post is displayed, and blog.hamlet
could contain the full blog.
blog.hamlet
的以下内容不起作用:
$forall post <- posts
^{widgetFile "blogpost")
那么,将一个小部件嵌入另一个小部件的正确语法是什么?
So, what is the correct syntax to embed one widget inside another?
推荐答案
Hamlet语法不支持将模板Haskell拼接嵌入其中,这使您想要执行的代码无法实现.相反,您需要在Haskell中创建一个辅助函数,例如:
The Hamlet syntax does not support embedding Template Haskell splices inside of it, which makes the code you're looking to do impossible. Instead, you need to create a helper function in Haskell, e.g.:
blogpost post = $(widgetFile "blogpost")
然后在blog.hamlet中,您可以:
Then in blog.hamlet, you can have:
$forall post <- posts
^{blogpost post}
这篇关于我如何使用widgetFile在另一个文件中包含一个hamletfile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!