Snap: getting form data and "if"

I don't seem to understand how to get the form data using the heist. I've just started learning Haskell web frameworks, but the documentation is a bit ... poor to say the least. The snap site's narrow hashing tutorial makes no mention of forms. So, given a simple html form, how do I get the form data to process in my handler function? Can anyone point me to a tutorial, Google is just holding onto this? Or maybe a short example ...

Also where can I get information about conditional control? Let's say if I want to conditionally include certain parts of html in my page, how do I do it using a heist? Basically, where is the "if"?



source to share

1 answer

See Using Digestive Functions with Heist for a good guide to simple forms and mighty musings on heist. If you plan on using multipart/form-data

, use the module Snap.Util.FileUploads


You can use Splice

to create content based on conditions.
A Splice

returns the list Node


mySplice = do
  -- get environment conditions
  -- condition could be passed in as a parameter 
  if condition 
     then return [] -- do nothing
     else return [TextNode "some content"] -- see Text.XmlHtml


Then you bind that splice to a tag using something like:

bindSplice myTag mysplice defaultHeistState

And place <myTag/>

in your template. When Heist

the template renders, it will evaluate the splice when it encounters the tag and inserts the value in its place.



All Articles