On native javascript, it would be something like this:

HTML:

<div class="btns"></div> <div class="btns"></div> 

Js:

 var buttons = document.querySelectorAll('.btns'); for(i=0; i<buttons.length; i++){ buttons.classList.add('btn_' +i); } 

Pug:

 - var modalList = [{ title: "ΠœΠ½ΠΎΠ³ΠΎΠΊΠ°ΠΌΠ΅Ρ€Π½Π°Ρ съСмка", posterImage: "content/video.jpg", description: 'ΠœΡ‹ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌ ΠΊΠ°ΠΌΠ΅Ρ€Ρ‹ Panasonic, Sony, Blackmagic, Go Pro.БъСмка Π½Π° нСсколько ΠΊΠ°ΠΌΠ΅Ρ€ с Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒΡŽ прямой трансляции, ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ΠΎΡ€Ρ‹, ΠΏΠ»Π°Π·ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΏΠ°Π½Π΅Π»ΠΈ. Онлайн трансляции Π² сСти Π˜Π½Ρ‚Π΅Ρ€Π½Π΅Ρ‚: 720Ρ€, 1080Ρ€, 4К.Π’ нашСм арсСналС ΠΌΡƒΠ»ΡŒΡ‚ΠΈΡ€ΠΎΡ‚ΠΎΡ€Ρ‹ для съСмки Π²Π΅Ρ€Ρ…Π½ΠΈΡ… ΠΏΠ»Π°Π½ΠΎΠ² с 3-Ρ… осСвой стабилизациСй ΠΈ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒΡŽ ΠΏΠ΅Ρ€Π΅Π΄Π°Ρ‡ΠΈ сигнала Π½Π° ΠΏΡƒΠ»ΡŒΡ‚ Π²ΠΈΠ΄Π΅ΠΎΠΈΠ½ΠΆΠ΅Π½Π΅Ρ€ΠΎΠ² (с дальнСйшСй трансляциСй Π½Π° экраны ΠΈΠ»ΠΈ Π² ΡΠ΅Ρ‚ΡŒ).ΠšΠΈΠ½Π΅ΠΌΠ°Ρ‚ΠΎΠ³Ρ€Π°Ρ„ΠΈΡ‡Π΅ΡΠΊΠΈΠ΅ ΠΊΡ€Π°Π½Ρ‹ ΠΈ Ρ‚Π΅Π»Π΅ΠΆΠΊΠΈ ΠΎΠ±Π΅ΡΠΏΠ΅Ρ‡ΠΈΠ²Π°ΡŽΡ‚ ΠΏΠΎΠ΄Π²ΠΈΠΆΠ½ΠΎΡΡ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ ΠΈ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡƒΡŽ ΠΏΠ»Π°Π²Π½ΠΎΡΡ‚ΡŒ ΠΊΠ°Π΄Ρ€Π°. Вросовая гиростабилизированная систСма подвСса с Π΄Π»ΠΈΠ½ΠΎΠΉ кабСльной Π»ΠΈΠ½ΠΈΠΈ Π΄ΠΎ 100 ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² позволяСт ΡΠ½ΠΈΠΌΠ°Ρ‚ΡŒ большиС спортивныС мСроприятия ΠΈ ΠΊΠΎΠ½Ρ†Π΅Ρ€Ρ‚Ρ‹ нСпосрСдствСнно Π½Π°Π΄ зритСлями.Благодаря оптичСским удлинитСлям сигнала Ρ€Π°Π±ΠΎΡ‚Π° ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ² ΠΏΡ€ΠΎΡ…ΠΎΠ΄ΠΈΡ‚ Π½Π° Π·Π½Π°Ρ‡ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠΌ ΡƒΠ΄Π°Π»Π΅Π½ΠΈΠΈ ΠΎΡ‚ ΠΏΡƒΠ»ΡŒΡ‚ΠΎΠ²ΠΎΠΉ. Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ пСрСдаСтся Π² Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Π΅ высокой чСткости.' }, {title: "blabla"} ]; mixin modal-tackles(tackles) .modal.modal-contact.fade.tackles__modal_(здСсь Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ ΠΈΠ½ΠΊΡ€Π΅ΠΌΠ΅Π½Ρ‚)(tabindex="-1", role="dialog", aria-labelledby="exampleModalLabel") .modal-dialog(role="document") .modal-content .modal-header span= tackles.title button.close(type="button",data-dismiss="modal", aria-label="Close") span(aria-hidden="true") x .modal-body for tackles in modalList +modal-tackles(tackles) 
  • and how is html being generated now? - Grundy
  • Here is the documentation - Hangeldy Ilebaev
  • @ Hangeldy Ilebaev, I can read, thanks, I need an example - GoodNew5
  • @Grundy, if you're talking about what's going on in my template engine, then I made changes to the question) - GoodNew5
  • yes about it. Where do you want to add indexes here? but I see - Grundy

1 answer 1

Instead of for in this case, it is better to use each , since it allows you to get the index of the current iteration.

Further this index needs to be transferred to mixin.

Since classes do not support interpolation, the class that needs to be collected dynamically needs to be transferred to attributes.

In the end, you should get something like this:

 for tackles, index in modalList +modal-tackles(tackles, index) 

And in mixin:

 mixin modal-tackles(tackles, index) .modal.modal-contact.fade(class=`tackles__modal_${index}`, tabindex="-1", role="dialog", aria-labelledby="exampleModalLabel") 
  • needles for the Christmas tree, I’ve done that only I wrote "class = tackles__modal_ +index" вмСсто: "class= tackles__modal_ $ {index}", AT SHOWER) - GoodNew5
  • Well, generally speaking, your version also had to work, maybe you forgot to transfer the index itself to the mixin, but the syntax was incorrect, it should be something like this: (class="tackles__modal_"+index - Grundy
  • @ GoodNew5, yeah, in the mixin call, you don’t pass the index, so inside it it is undefined - Grundy