Use interpolation in Jade inside each

1

I am trying to iterate with an each in Jade, to generate a menu, but inside the to the href I do not iterate the array pages using the interpolation # {page}. However outside that label if it works.

  -var paginas = ["inicio","nosotros","servicios","clientes","contacto"]

 ul
   each pagina in paginas
     li: a(href="#{pagina}.html") #{pagina}

Which generates the following:

    <ul>
      <li><a href="#{pagina}.html">inicio</a></li>
      <li><a href="#{pagina}.html">nosotros</a></li>
      <li><a href="#{pagina}.html">servicios</a></li>
      <li><a href="#{pagina}.html">clientes</a></li>
      <li><a href="#{pagina}.html">contacto</a></li>
    </ul>

Additional information: I am using prepros to compile.

    
asked by noobChileno 26.12.2016 в 00:21
source

3 answers

1

your array is not being recognized

if you delete it and work like that?

ul
    each pagina in ["inicio","nosotros","servicios","clientes","contacto"]
        li: a(href="#{pagina}.html") #{pagina}

which generates the following:

<ul>
  <li><a href="inicio.html">inicio</a>
  </li>
  <li><a href="nosotros.html">nosotros</a>
  </li>
  <li><a href="servicios.html">servicios</a>
  </li>
  <li><a href="clientes.html">clientes</a>
  </li>
  <li><a href="contacto.html">contacto</a>
  </li>
</ul>

look at the probe online and it works

    
answered by 26.12.2016 в 00:30
1

This has helped me and has not given me any errors, I hope it helps you.

-var paginas = ["inicio", "nosotros", "servicios", "clientes", "contacto"]

ul
  each pagina, i in paginas
    li: a(href= paginas[i] + ".html") #{pagina}
    
answered by 14.03.2017 в 23:25
0

I did 3 different tests (not much) with the array you supplied, use codepen.io to do the tests, and even though a .pug some of these forms can help you.

Here the code:

    -var paginas = ["inicio","nosotros","servicios","clientes","contacto"]
    ul
        each pagina in paginas
            li: a(href="#{pagina}.html") #{pagina}
    ul
        each uno, i in paginas
            li: a(href=uno[i] +".html") #{uno}
    ul
        each otro in paginas
            li: a(href=otro[$index] +".html")= otro
    
answered by 06.06.2017 в 22:25