Haskell Snap Framework - Dynamic hyperlinks with Heist -
i trying create dynamic links using heist templating system. problem links appearing text rather being interpreted html. there specific method create dyamic lists heist?
the function link constructed:
rendercategories :: monad m => db.category -> i.splice m rendercategories (db.category catid catname catdesc) = i.runchildrenwithtext [ ("categoryid", t.concat $ ["<a href='http://localhost:8000/thread_home?cateid=", t.pack . show $ catid, "'>", t.pack . show $ catid, "</a>"]) , ("categoryname", catname) , ("categorydesc", catdesc)]
the tag appears "http://localhost:8000/thread_home?cateid=1'>1" text on webpage. , source shows follows:
<a href='http://localhost:8000/thread_home?cateid=1'>1</a>
i figure need have print actual < , > not sure how achieve this. running runchildrenwithtext populate heist template changing runchildrenwith requires splices instead of text , instead of attempting hoping there way runchildrenwithtext without '<' , '>' being converted '<' , '>'. appreciated!
edit
i trying manually create link using:
rendercategories :: monad m => db.category -> i.splice m rendercategories (db.category catid catname catdesc) = i.runchildrenwith [ ("categoryid", return $ x.element "a"[("href", "http://localhost")] $ x.textnode (t.pack $ show catid))]
however encountering 2 errors:
couldn't match type `x.node' `[x.node]' expected type: i.splice m actual type: heist-0.11.1:heist.types.heistt m m x.node in expression: return $ x.element "a" [("href", "http://localhost")] $ x.textnode (t.pack $ show catid)
and
couldn't match expected type `[x.node]' actual type `x.node' in return type of call of `x.textnode' in second argument of `($)', namely `x.textnode (t.pack $ show catid)'
i not understand these errors @ moment , appreciated.
working function both returning link , normal text:
rendercategories :: monad m => db.category -> i.splice m rendercategories (db.category catid catname catdesc) = i.runchildrenwith [( "categoryid", return $ [x.element "a" [("href", t.concat $ ["http://localhost:8000/thread_home?cateid=", t.pack $ show catid] )] [x.textnode (t.pack $ show catid)] ] ) , ("categoryname", i.textsplice catname) , ("categorydesc", i.textsplice catdesc)]
the behavior seeing intended. reason having problems because you're using runchildrenwithtext
higher level function designed situations returning text nodes. meant when want actual text on page. seeing correct way achieve that.
a splice computation returns list of nodes.
type splice n = heistt n n [node]
node
representation of dom haskell types, if want return link, should this:
return $ [element "a" [("href", "http://localhost")] [textnode (t.pack $ show catid)]]
to use kind of splice, you'll need use runchildrenwith
instead of runchildrenwithtext
.
if manual creation of node
s seems ugly you, there's more convenient option. if import module text.blaze.renderer.xmlhtml, you'll find functions there let generate node
trees using blaze-html syntax.
Comments
Post a Comment