Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda