我正在尝试使用Heist模板系统创建动态链接。问题是链接是以文本形式出现的,而不是被解释为html。有什么特定的方法可以用Heist创建这样的动态列表吗?
构建链接的函数:
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)]标签在网页上显示为"home?cateid=1'>1“文本。消息来源显示如下:
<a href='http://localhost:8000/thread_home?cateid=1'>1</a>我想,我需要让它打印实际<和>,但我不知道如何实现这一点。由于我目前正在运行runChildrenWithText来填充这个Heist模板,更改为runChildrenWith只需要剪接而不是文本,所以我希望没有将'<‘和’>转换为'<‘和'>’>的情况下,有一些方法可以实现runChildrenWithText。任何帮助都是非常感谢的!
编辑
我正在尝试使用以下方法手动创建链接:
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))]然而,我遇到了两个错误:
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)和
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)'我目前并不真正理解这些错误,任何帮助都是非常感谢的。
返回链接和正常文本的工作函数:
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)]发布于 2013-08-07 18:47:29
你所看到的正是你想要的行为。出现问题的原因是因为您使用的是runChildrenWithText,它是为返回文本节点的情况而设计的更高级别的函数。它的意思是当你想要在你的页面上的实际文本。你所看到的是实现这一目标的正确途径。
拼接是一种返回节点列表的计算。
type Splice n = HeistT n n [Node]Node是DOM的Haskell类型的表示形式,因此,如果您想返回链接,应该执行如下操作:
return $ [Element "a" [("href", "http://localhost")] [TextNode (T.pack $ show catid)]]要使用这种拼接,您需要使用runChildrenWith而不是runChildrenWithText。
如果手动创建Node对您来说很难看,那么还有一个更方便的选择。如果导入模块Text.Blaze.Renderer.XmlHtml,您将在其中找到允许使用烈火-html语法生成Node树的函数。
https://stackoverflow.com/questions/18111023
复制相似问题