Frage

The below pyjade code causes an internal server error. When the #{module.key} is taken outside the href it works fine. Any ideas?

table
    // the table isn't working perfectly but leo is making responsive 
    // anyway, will merge that version
    each module, m in modules
      if (m % 5 == 0)
        tr
          td
            a(href='#{module.key}') #{module.name}
      else 
        td
          a(href="#{module.key}") #{module.name}

enter image description here

War es hilfreich?

Lösung 3

What one has to do is divide up the array into a 2D array in the backend and then iterate over the rows in the jade template. Within each row iteration, write a tr and iterate through the cols of that row. When iterating through the cols, write the td and its content.

Andere Tipps

Based on the error which is complaining about a TypeError with each module, m in modules with this line and looking at the docs for iteration of jade http://jade-lang.com/reference/#iteration suggests to me that the index derived in the iteration is a string.

You should try

each module, m in modules
    (int(m) % 5 == 0)

It's Syrus, creator of pyjade Python package. Pyjade doesn't cast your vars inside #{} as strings, so you have to do it yourself.

The following example should work

table
    // the table isn't working perfectly but leo is making responsive 
    // anyway, will merge that version
    each module, m in modules
      if (m % 5 == 0)
        tr
          td
            a(href='#{str(module.key)}') #{module.name}
      else 
        td
          a(href="#{str(module.key)}") #{module.name}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top