Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
Inject html with unclosed tags with alpine.js

What is the proper way to inject a portion of html that have unclosed tags?
I use the modulus in x-if for determine when close the row and start a new one.
This code is not working since the template div is immediately closed.

<template x-if="rowCount % 10 === 0"> 
  <div>                                 
  <!-- HTML to inject--> </div><div class="m-0 flex justify-between">  
  </div>
</template>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The proper way is to partition the input data to the required shape, then use two loops. Using this method we don't have to deal with unclosed tags and the code is more readable.

<script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>

<script>
function partition_array(input, amount) {
  let output = [];

  for (let i=0; i < input.length; i += amount) {
    output[output.length] = input.slice(i, i + amount);
  }

  return output;
}
</script>


<div x-data="{array_of_arrays: partition_array([...Array(9).keys()], 3)}">
  <div>
    <template x-for="array in array_of_arrays">
      <div>
        <template x-for="item in array">
        <span x-text="`${item} `"></span>
        </template>
      </div>
    </template>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda