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

185
Views
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
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!