1

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

Gobi Dasu
  • 459
  • 1
  • 6
  • 22

3 Answers3

0

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)
Tim Hoffman
  • 12,976
  • 1
  • 17
  • 29
  • I'm using pyjade, not which is not exactly jade. Actually I realized that the syntax above is wrong. What I have to do: a(href=module.key). The issue I am having is now is that pyjade adds extra double quotes exactly like the ""Tim"" in : https://github.com/SyrusAkbary/pyjade/issues/67 – Gobi Dasu Feb 18 '14 at 03:13
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}
Syrus Akbary Nieto
  • 1,249
  • 12
  • 20
0

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.

Gobi Dasu
  • 459
  • 1
  • 6
  • 22