Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don's suggestion of blaze-html is one way to do it, but I find that when I do it that way I have more of a tendency to violate the commonly used MVC design pattern by embedding the view (in this case the HTML) into your Haskell code. In some cases if you're just trying to do something quick and dirty this may be the thing to do. But if you want this to fit into a larger application in a way that separates the view from the controller and allows designers to work with it who are unfamiliar with Haskell, then you might be better off using the Heist template system.</p> <p>We have a Heist tutorial <a href="http://snapframework.com/docs/tutorials/heist" rel="nofollow">here</a>. I also recently wrote a series of <a href="http://softwaresimply.blogspot.com/" rel="nofollow">blog posts</a> about just this sort of thing. The <a href="http://softwaresimply.blogspot.com/2011/04/views-controllers-and-heist.html" rel="nofollow">second post in the series</a> in particular is probably the most relevant to your question. Here's some code that does something like what you want:</p> <pre><code>names :: [(Text,Text)] names = [("Alice", "Anderson"), ("Bob", "Brown")] nameSplice :: (Text, Text) -&gt; Splice Application nameSplice name = runChildrenWithText [("firstName", fst name), ("lastName", snd name)] namesSplice :: Splice Application namesSplice = mapSplices nameSplice names </code></pre> <p>After you bind the names splice somewhere in your application with <code>bindSplice "names" namesSplice</code> you can get at this data from a template like this:</p> <pre><code>&lt;table&gt; &lt;names&gt; &lt;tr&gt;&lt;td&gt;&lt;firstName/&gt;&lt;/td&gt;&lt;td&gt;&lt;lastName/&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/names&gt; &lt;/table&gt; </code></pre> <p>The nice thing about this is that the web designer has complete control over how the names are displayed. If they needed to change the display to say an unordered list in the format "lastname, firstname" that would be very easy to do here without needing to recompile your application.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload