thanks mightybyte for helping me with this on irc. after 8 hours, when I was forbidden to answer myself, here is my version of the same answer:
build a splice that reads the qu1.tpl template, creates an instance of it (that is, fills the name and number of the question in the list) and returns it. heist functionTemplate helps you with this. (This splice is called splicex in the pseudo-code below.)
write another splice that splicex adds up so that you get a list of (instances) of questions instead of one. (functional splicing in pseudo-code.)
use bindSplice instead of bindString.
pseudocode (tested, then modified and out of context) -
... -> let splice :: Monad m => Splice m splice = foldM (\ ts (s, i) -> liftM ((++) ts) $ splicex (quName, quNumber)) [] (zip questionName [0..]) splicex :: Monad m => (String, Int) -> Splice m splicex (quName, quNumber) = do mt <- callTemplate "qu1" [ ("question-name", Data.Text.pack quName) , ("question-number", Data.Text.pack $ show quNumber) ] case mt of Nothing -> error "splice rendering failed." Just (t :: Template) -> return t in -- fill in the list of (instatiated) questions heistLocal (bindSplice "qulist" splice) $ -- before that, instantiate the overall page instantiatePage $ render "qu"
btw, my original avatar is too weak to create new tags. can anyone mark this "heist"?
links:
http://snapframework.com/
#snapframework channel on IRC network freenode.
http://snapframework.com/docs/tutorials/heist
source share