Generación Html recursiva con Hamlet

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>

Tengo un 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?

preguntado el 28 de agosto de 12 a las 11:08

1 Respuestas

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.

(Inspirado por esta respuesta.)

contestado el 23 de mayo de 17 a las 13:05

Thanks. I tried something very similar, but I wasn't sure it worked as I hit some hard to understand type error. - yogsototh

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.