Lucid: Conditional rendering

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 () 
 
0
Kudos
 
0
Kudos

Now read this

When linking goes wrong

I have a Haskell application that needs to be deployed to a server. I took the route of having CircleCI copy the binary after stack install to a S3 bucket, and have an Ansible playbook that copies the binary to the server and launch it... Continue →