如何在不应用模板的情况下在文件中插入$ key $ s?

时间:2017-10-08 19:13:20

标签: hakyll

在Jekyll中,可以有一个看起来像

的文件
---
title: Whatever
layout: null
---

<h1>{{ title }}</h1>

{{ title }}将被插值,但layout: null表示文件内容不会被包装在任何类型的模板中。

Hakyll的等价物是什么?换句话说,如果我有一个像

这样的自包含文件
<h1>$title$</h1>

我需要将哪种块传递给compile以便插入$title$值,不用将页面内容包装在某个模板中?

1 个答案:

答案 0 :(得分:0)

答案(感谢#hakyll频道中的erasmas!)是使用

编译你的页面
getResourceBody >>= applyAsTemplate theContext

其中theContextContext String的实例,其中包含您想要的字段。

以下是您如何使用此编译器的玩具示例:

main :: IO ()
main = hakyll $ do
    match "index.html" $ do
        route idRoute
        compile $ getResourceBody >>= applyAsTemplate indexContext

indexContext :: Context String
indexContext = mconcat
    [ constField "title" "My Website"
    , defaultContext
    ]