我如何使用widgetFile在另一个文件中包含一个hamletfile? [英] How can I include an hamletfile inside another using widgetFile?

查看:68
本文介绍了我如何使用widgetFile在另一个文件中包含一个hamletfile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于可重用性,我想在另一个内部重用一个小部件.例如,小部件文件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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆