Example: Request information

{-# LANGUAGE OverloadedStrings, TypeFamilies, TemplateHaskell, QuasiQuotes, TypeFamilies, MultiParamTypeClasses, GADTs #-} import Yesod import Data.Text ( Text ) import Data.List (sortBy) import Data.Ord (comparing) data Person = Person { personName :: Text , personAge :: Int } people :: [ Person ] people = [ Person "Miriam" 25 , Person "Eliezer" 3 , Person "Michael" 26 , Person "Gavriella" 1 ] data People = People mkYesod "People" [parseRoutes| / RootR GET |] instance Yesod People instance RenderMessage People FormMessage where renderMessage _ _ = defaultFormMessage getRootR :: Handler RepHtml getRootR = defaultLayout [whamlet| <p> <a href= "?sort=name" > Sort by name \ | # <a href= "?sort=age" > Sort by age \ | # <a href= "?" > No sort ^{showPeople} |] showPeople :: Widget showPeople = do msort <- lift $ runInputGet $ iopt textField "sort" let people' = case msort of Just "name" -> sortBy (comparing personName) people Just "age" -> sortBy (comparing personAge) people _ -> people [whamlet| <dl> $forall person <- people' <dt>#{personName person} <dd>#{show $ personAge person} |] main :: IO () main = warpDebug 3000 People