@@ -4,6 +4,7 @@ module Hakyll.Web.Template.Context
4 ( ContextField (..)
4 ( ContextField (..)
5 , Context (..)
5 , Context (..)
7 , constField
8 , constField
8 , listField
9 , listField
9 , listFieldWith
10 , listFieldWith
@@ -27,7 +28,7 @@ module Hakyll.Web.Template.Context
29--------------------------------------------------------------------------------
30--------------------------------------------------------------------------------
30−import Control.Applicative (Alternative (..), (<$>))
31+import Control.Applicative (Alternative (..), (<$>), pure)
31import Control.Monad (msum)
32import Control.Monad (msum)
32import Data.List (intercalate)
33import Data.List (intercalate)
33import qualified Data.Map as M
34import qualified Data.Map as M
@@ -97,6 +98,17 @@ field
97field key value = field' key (fmap StringField . value)
98field key value = field' key (fmap StringField . value)
101+--------------------------------------------------------------------------------
102+-- | Creates a 'field' to use with the @$if()$@ template macro.
107+boolField name f = field name (\i -> if f i
108+ then pure (error $ unwords ["no string value for bool field:",name])
100--------------------------------------------------------------------------------
112--------------------------------------------------------------------------------
101-- | Creates a 'field' that does not depend on the 'Item'
113-- | Creates a 'field' that does not depend on the 'Item'
102constField :: String -> String -> Context a
114constField :: String -> String -> Context a