I am trying to loop through a list of products in hamlet each product has a category. I would like to break down the output to group into the categories with a list of products below each category heading. Is there a way to do this in hamlet while looping through my products. What I currently have below is showing the heading for every product. I think I might be going about this all wrong.
$if null products
<p>No products
$else
<div class="list-group menu">
$forall product <- products
<div class="list-group-item">
<h4 class="list-group-item-heading">#{categoryName $snd product}
<div class="list-group-item">
<div class="container-fluid">
<div class="col-md-12">
<p>#{productName $fst product} - #{productPrice $fst product}
And below is the bit of code thats gets the products from the database of type [(Product Category)]
products <- runDB $ selectList [ProductName !=. ""] [LimitTo 10] >>= mapM (\qe@(Entity _ q) -> do
Just category <- get $ productCategory q
return (q, category))