@@ -18,6 +18,7 @@ module Hakyll.Web.Template.Context
1818 , urlField
1919 , pathField
2020 , titleField
21+ , snippetField
2122 , dateField
2223 , dateFieldWith
2324 , getItemUTC
@@ -147,6 +148,22 @@ mapContext f (Context c) = Context $ \k a i -> do
147148 "Hakyll.Web.Template.Context.mapContext: " ++
148149 "can't map over a ListField!"
149150
151+--------------------------------------------------------------------------------
152+-- | A context that allows snippet inclusion. In processed file, use as:
153+--
154+-- > ...
155+-- > $snippet("path/to/snippet/")$
156+-- > ...
157+--
158+-- The contents of the included file will not be interpolated.
159+--
160+snippetField :: Context String
161+snippetField = functionField "snippet" f
162+ where
163+ f [contentsPath] _ = loadBody (fromFilePath contentsPath)
164+ f _ i = error $
165+ "Too many arguments to function 'snippet()' in item " ++
166+ show (itemIdentifier i)
150167
151168--------------------------------------------------------------------------------
152169-- | A context that contains (in that order)