@@ -4,6 +4,7 @@ module Hakyll.Web.Template.Context
44 ( ContextField (..)
55 , Context (..)
66 , field
7+ , boolField
78 , constField
89 , listField
910 , listFieldWith
@@ -27,7 +28,7 @@ module Hakyll.Web.Template.Context
2728
2829
2930--------------------------------------------------------------------------------
30−import Control.Applicative (Alternative (..), (<$>))
31+import Control.Applicative (Alternative (..), (<$>), pure)
3132import Control.Monad (msum)
3233import Data.List (intercalate)
3334import qualified Data.Map as M
@@ -97,6 +98,17 @@ field
9798field key value = field' key (fmap StringField . value)
9899
99100
101+--------------------------------------------------------------------------------
102+-- | Creates a 'field' to use with the @$if()$@ template macro.
103+boolField
104+ :: String
105+ -> (Item a -> Bool)
106+ -> Context a
107+boolField name f = field name (\i -> if f i
108+ then pure (error $ unwords ["no string value for bool field:",name])
109+ else empty)
110+
111+
100112--------------------------------------------------------------------------------
101113-- | Creates a 'field' that does not depend on the 'Item'
102114constField :: String -> String -> Context a