教程页面不是一个完整的示例。 item
不是对某些功能的引用。它只是一个占位符名称Item
。通常你会从许多其他“编译器”pandocCompiler
或其中之一获得它。在这个例子中,就像它的任何其他用途一样。唯一的区别是它将绑定到模板中的预告文本。loadAndApplyTemplate
$teaser$
也就是说,这并不是一个很好的示例,因为您通常希望在列出多个帖子的页面上使用预告文本。这可能涉及使用listField
来制作您将在模板中迭代的帖子集合。例如,这是我的索引页面的规则:
match "index.html" $ do
route idRoute
compile $ do
posts <- fmap (take indexRecentPostCount) . recentFirst =<< loadAllSnapshots postsPattern "postContent"
let indexCtx =
constField "title" "Home" <>
baseCtx
getResourceBody
>>= applyAsTemplate (listField "posts" (teaserField "teaser" "postContent" <> postCtx) (return posts) <> indexCtx)
>>= loadAndApplyDefaultTemplate indexCtx
>>= relativizeUrls
在这种情况下,“项目”是getResourceBody
返回的,即index.html
. 这绑定$posts$
到帖子列表。忽略元数据,我index.html
的只是:
$for(posts)$
$partial("templates/teaser.html")$
$endfor$
$teaser$
然后绑定在template/teaser.html
模板中。