1

I have this function in my script:

function DoThing (num){
 //Do thing
});

num refers to each item in a list I created earlier in the script. DoThing(1) will activate for the first item and so on.

I'm working with a Jinja2 template for a multi-page website, and I want to put the function with a custom num argument in each template.

In the first page, I would have DoThing(1). Second page would be DoThing(2). My goal is to add new items and have the template update as needed based on the length of my list.

Is this possible?

0

1 Answer 1

3

You can set the num variable in the beginning of your template:

{% set num = 1 %}

and call your Javascript function like:

<script>
    DoThing({{ num }});
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.