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