【问题标题】:Recursive Html generation with Hamlet使用 Hamlet 生成递归 Html
【发布时间】:2012-08-28 10:24:07
【问题描述】:

我想生成一个评论树。

<ul>
   <li> First comment
      <ul> 
        <li> reply to first comment
        <li> another reply to first comment
      </ul>
   </li>
 </ul>

我有一个Tree (Entity Comment) 结构。 我想拥有 hamlet 的所有好处(#{commentContent comment} 将受到 XSS 保护)。

如何使用 Hamlet 实现递归 Html 渲染?

【问题讨论】:

    标签: haskell yesod hamlet


    【解决方案1】:

    您可能无法在普通的 hamlet 中执行此操作,但您可以创建一个辅助函数 commentTree,您可以使用 ^{commentTree comments} 访问它。该函数将返回 Hamlet,并且可以自己使用 [hamlet|&lt;li&gt;^{commentTree subcomment}|] 进行递归,使用 [hamlet|&lt;u&gt;#{commentContent comment}|] 进行安全插值。

    (灵感来自this answer。)

    【讨论】:

    • 谢谢。我尝试了一些非常相似的方法,但我不确定它是否有效,因为我遇到了一些难以理解的类型错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 2019-10-18
    • 2018-06-23
    • 2016-07-19
    • 1970-01-01
    相关资源
    最近更新 更多