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

187
Vistas
Mustache.render() Renders without the Arguments (Javascript)

I'm creating a website for my business, and I'm trying to load a list of images using the library Mustache, but the function render is rendering the template without the data. Here is the code:

the relevant part of gallery.hbs:

<div id="img-container" class="container-fluid">
        <div class="section-header">
            <h2 class="wow fadeInDown animated" style="color: #0a0a0a">Gallery</h2>
        </div>

        <script id="img-template" type="text/html">
                <div class="row no-gutter">
                <div class="col-lg-3 col-md-6 col-sm-6 work"> <a href="{{img_url}}" class="work-box"> <img src="{{img_url}}" alt="">
                    <div class="overlay">
                        <div class="overlay-caption">
                            <p><span class="icon icon-magnifying-glass"></span></p>
                        </div>
                    </div>
                    <!-- overlay -->
                </a> </div>
            </div>
        </script>
    </div>

And gallery.js:

let imgTemp = document.querySelector("#img-template").innerHTML;
let $imgContainer =  document.getElementById("img-container");

for(let i = 1; i <= 8; i++) {
    let url = `images/portfolio/0${i}.jpg`
    let jsonData = {img_url: url};

    let tmpHtml = Mustache.render(imgTemp, jsonData);
    console.log(tmpHtml); /* For debugging */

    $imgContainer.insertAdjacentHTML("beforeend", tmpHtml);
}

I have a list of images in the directory images/portfolio/ but cannot view them on my website. In addition, I logged the rendered tags for debugging, and I can view the tags, but without the img_url value:

<div class="row no-gutter">
<div class="col-lg-3 col-md-6 col-sm-6 work"> <a href="" class="work-box"> <img src="" alt="">
    <div class="overlay">
        <div class="overlay-caption">
            <p><span class="icon icon-magnifying-glass"></span></p>
        </div>
    </div>
<!-- overlay -->
</a> </div>
</div>

Is there something that I missed? Thanks for the help.

about 4 years ago · Juan Pablo Isaza
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