I have a form written in Lucid and I need to add a prompt to the user based on some condition:
someForm :: Bool -> Html ()
someForm condition = body_ $
...
renderIfCondition
where
renderIfCondition
| condition = div_ $ p_ [] "Some prompt message"
| otherwise = ...
The question was what do I place in the otherwise
clause. Initially, as a placeholder, I wrote
otherwise = makeElement "div" mempty
which when rendered, displayed an empty div
. That worked (sort of) but was not ideal. If I didn’t have something to say, then there should be nothing. After looking through Lucid.Base
, I found
instance Monad m => Monad (HtmlT m) where
return a = HtmlT (return (mempty,a))
...
So my renderIfCondition
becomes
renderIfCondition
| condition = ...
| otherwise = return ()