1

I'd like to generate a comment tree.

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

I have a Tree (Entity Comment) structure. I would want to have all the benefice of hamlet (#{commentContent comment} will be protected against XSS).

How could I achieve a recursive Html rendering with Hamlet?

1 Answer 1

4

You probably cannot do it in plain hamlet, but you can create a helper function commentTree that you can access using ^{commentTree comments}. This function would return Hamlet and can itself use [hamlet|<li>^{commentTree subcomment}|] for the recursion and [hamlet|<u>#{commentContent comment}|] for the safe interpolation.

(Inspired by this answer.)

1
  • Thanks. I tried something very similar, but I wasn't sure it worked as I hit some hard to understand type error.
    – yogsototh
    Aug 28, 2012 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.