0

Node.js: I am iterating through the contents of title2 using for loop. But to make the div tag unique, I am using the {{var i=0;}} it gives the following error expected variable end. I also tried {% var i = 0; %} but that too doesnt seem to work I have put the end tag but it does not seem to work. I might mostly be putting the wrong end tag but I cannot figure out the right one. Can I know if this is the right way to declare a variable and end it? Also if this is the right way to increment the variable in the HTML file?

{% extends "base.html" %}

{% block content %}
<div><h4>Python Examples</h4>
    {% for contentPackage in contentPackages %}
    {% for ex in contentPackage.title2 %}
    {{var i=0;}}


    <div class="contentPackage col-md-4">
        <h5 style="font-size: 15px;padding-left: 3px" class="packageTitle bg-primary">{{ ex['topic_name'] }}
            <a href="javascript:void(0)" class="easyui-link" onclick="javascript:$('#pane'+i).panel('open')"> [Open</a>
            <a href="javascript:void(0)" class="easyui-link" onclick="javascript:$('#pane'+i).panel('close')">Close] </a>
        </h5>

        <div id="pane{{i}}"  closed="true" openAnimation="slide" closeAnimation="slide" class="easyui-panel" title="{{ ex['topic_name'] }}" style="padding:2px;">

            <div class="contentPackageMain">
                <div class="teaserContent">
                    <ol>
                       <p>Something</p>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    {{i++}}
    {{endvar}}
    {% endfor %}
    {% endfor %}
</div>
{% endblock %}
mscdex
  • 104,356
  • 15
  • 192
  • 153
  • You seem to be missing some key information: What templating system are you using here? – nrabinowitz Nov 23 '15 at 17:59
  • i am using the `nunjucks` templating system – Hardik Vasa Nov 23 '15 at 18:10
  • 1
    Instead of your `i` try using built-in index `{{ loop.index }}` ,https://mozilla.github.io/nunjucks/templating.html#for – Molda Nov 23 '15 at 18:24
  • Thank you for the resource...looks like thats what I needed...but due to some reason it doesnt seem to work...am I doing it right in the onclick method? `onclick="javascript:$('#pane'+((loop.index).toString())).panel('open')"` – Hardik Vasa Nov 23 '15 at 18:36
  • 1
    Okay I figured that out...it should be something like this... `onclick="javascript:$('#pane'+'{{loop.index}}').panel('open')"` thanks a lot...hope i could upvote your answer – Hardik Vasa Nov 23 '15 at 18:41

0 Answers0