David Crook
David Crook

Reputation: 2730

Use Jinja Variable to generate n elements

I want to use Jinja variables to generate n options in a drop down. Here is an example:

    Session Select: <br>
    {{ sessions }}
    <select style="color:black">
        {% for session in sessions %}
            <li>{{ session }}</li>
        {% endfor %}
    </select> <br><br>

The value of sessions is:

['Session 1', 'Session 2', 'Session 3']

Any thoughts?

Upvotes: 0

Views: 397

Answers (3)

dizzyf
dizzyf

Reputation: 3693

Assuming no_sessions is your n value... I would try something like this:

Session Select: <br>
<select style="color:black">
    {% range number from 1 to no_sessions %}
        <option>Session {{ number }}</option>
    {% endrange %}
</select> <br><br>

(related to this question)

Upvotes: 1

SumanKalyan
SumanKalyan

Reputation: 1761

Session Select: <br>
<select style="color:black">
    {% for session in sessions %}
        <option value="{{ session }}">{{ session }}</option>
    {% endfor %}
</select> <br><br>

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 599708

To generate items within a select box you use the <option> tag, not <li>.

Upvotes: 0

Related Questions