Note that there are some explanatory texts on larger screens.

plurals
  1. POHaskell Snap Framework - Dynamic hyperlinks with Heist
    primarykey
    data
    text
    <p>I am trying to create dynamic links using the Heist templating system. The problem is that the links are appearing as text rather than being interpreted as html. Is there a specific method to create dyamic lists like this with Heist?</p> <p>The function where the link is constructed:</p> <pre><code>renderCategories :: Monad m =&gt; Db.Category -&gt; I.Splice m renderCategories (Db.Category catid catname catdesc) = I.runChildrenWithText [ ("categoryId", T.concat $ ["&lt;a href='http://localhost:8000/thread_home?cateid=", T.pack . show $ catid, "'&gt;", T.pack . show $ catid, "&lt;/a&gt;"]) , ("categoryName", catname) , ("categoryDesc", catdesc)] </code></pre> <p>The tag appears as "http://localhost:8000/thread_home?cateid=1'>1" text on the webpage. And the source shows it as follows:</p> <pre><code>&amp;lt;a href='http://localhost:8000/thread_home?cateid=1'&amp;gt;1&amp;lt;/a&amp;gt; </code></pre> <p>I figure that I need to have it print the actual &lt; and > but I am not sure how to achieve this. As I am currently running runChildrenWithText to populate this Heist template changing to just runChildrenWith requires splices instead of text and so instead of attempting this I am hoping there is some way to runChildrenWithText without the '&lt;' and '>' being converted to '&amp;lt' and '&amp;gt'. Any help is appreciated!</p> <p>EDIT</p> <p>I am trying to manually create the link using:</p> <pre><code>renderCategories :: Monad m =&gt; Db.Category -&gt; 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))] </code></pre> <p>However I am encountering two errors:</p> <pre><code>Couldn't match type `X.Node' with `[X.Node]' Expected type: I.Splice m Actual type: heist-0.11.1:Heist.Types.HeistT m m X.Node In the expression: return $ X.Element "a" [("href", "http://localhost")] $ X.TextNode (T.pack $ show catid) </code></pre> <p>and</p> <pre><code>Couldn't match expected type `[X.Node]' with actual type `X.Node' In the return type of a call of `X.TextNode' In the second argument of `($)', namely `X.TextNode (T.pack $ show catid)' </code></pre> <p>I do not really understand these errors at the moment and any help is appreciated.</p> <p>Working function for both returning the link and normal text:</p> <pre><code>renderCategories :: Monad m =&gt; Db.Category -&gt; 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)] </code></pre>
    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. 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