[英]How do I render a heist template with splices?
I'm trying to use renderWithSplices
- http://hackage.haskell.org/package/snap-1.0.0.0/docs/Snap-Snaplet-Heist.html#v:renderWithSplices 我正在尝试使用
renderWithSplices
- http: renderWithSplices
What is an idiomatic way to get a value of type Splices s
(for the second parameter to renderWithSplices
)? 什么是惯用的方式来获取
Splices s
类型的值(对于第二个参数renderWithSplices
)?
The heist tutorial has a couple examples of defining the Splices
type. 抢劫教程中有几个定义
Splices
类型的示例。
If you click on the Splices
link in the haddock you linked to above, we see that Splices
is defined as follows: 如果单击上面链接到的黑线
Splices
中的“ Splices
链接,我们将看到Splices
的定义如下:
type Splices s = MapSyntax Text s
If you then click on the MapSyntax
link, you're taking to the docs for the map-syntax
package. 如果您随后单击
MapSyntax
链接,则将MapSyntax
有关map-syntax
软件包的文档。 This is a small package defining some more convenient syntax for creating maps. 这是一个小程序包,定义了一些更方便的语法来创建地图。 There's an example at the top, but the general pattern is as follows:
顶部有一个示例,但一般模式如下:
mySplices = do
k1 ## v1
k2 ## v2
Since the previous definition told us that the keys are text, we can do the following to find out what the type of the values needs to be: 由于前面的定义告诉我们键是文本,因此我们可以执行以下操作来找出值的类型是什么:
someFunc = do
...
renderWithSplices "my-template" mySplices
...
mySplices = do
"foo" ## I.textSplice "bar"
If you have a recent enough GHC (I think 7.8 or higher), the underscore on that last line will create a type hole and cause the compiler to tell you what the type of the thing in that location should be. 如果您最近有足够的GHC(我认为是7.8或更高),那么最后一行的下划线将创建一个类型孔,并使编译器告诉您该位置的事物的类型。 Then you can write the appropriate thing of that type and it should be more obvious what to do from there.
然后,您可以编写该类型的适当内容,并且从那里开始应该更明显。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.