Browse files

More tutorial work

  • Loading branch information...
1 parent 496973d commit a23f27a548a3d053acf6c2bd4179d40485413a9e @mightybyte mightybyte committed Oct 30, 2012
Showing with 13 additions and 2 deletions.
  1. +13 −2 test/suite/Heist/Tutorial/CompiledSplices.lhs
15 test/suite/Heist/Tutorial/CompiledSplices.lhs
@@ -228,8 +228,19 @@ data in splices. But it has the simplification that it always generates
output the same way. Sometimes you might want a splice's output to have one
form in some cases and a different form in other cases. A simple example is a
splice that reads some kind of a key from a request parameter then looks that
-key up in some kind of map. If the key is present the splice outputs
-the value, otherwise it outputs an error message.
+key up in some kind of map. If the key is present the splice uses its child
+nodes as a view for the retrieved value, otherwise it outputs an error message.
+This pattern is a little tricky because you're making decisions about what to
+render based on runtime data, but the actual rendering of child nodes has to
+be done at load time. To bridge the gap and allow communication between load
+time and runtime processing we provide the Promise data type. A Promise is
+kind of like an IORef except that operations on them are restricted to the
+appropriate Heist context. You create a new empty promise in the HeistT n IO
+(load time) monad, and you operate on it in the RuntimeSplice monad.
+Here's an example of how to use a promise manually to render a splice
+differently in the case of failure.
< failingSplice :: MonadSnap m => C.Splice m
< failingSplice = do

0 comments on commit a23f27a

Please sign in to comment.