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

182
Views
How to call function using Nunjucks?

I want to call the jQuery function in HTML using Nunjucks, but it's giving me an error. I have imported the JS file into the HTML file.

Error: Unable to call 'fooName', which is undefined or falsey

Does anyone know why I can't call the function? Here is my code example:

<a class="btn" onclick="{{fooName(test)}}" href="#">Click me!</a>
$(document).ready(() => {
  const fooName = (name) => {
    console.log(`${this.name}`)
  };
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

My situation was a bit different but still I think it works in this case too

The idea is to add a function to the global window object

Within the view render method that passes variables to nunjucks I added this function

var self = this;

window.onClick = function (id) {
 // self.fetchData(id);
 // Do something
}

and within nunjucks

<a class="btn" onclick="window.onClick({{item.id}})">Click me!</a>

it works perfectly.

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!