Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!