Question about for loops in oTree

30 views
Skip to first unread message

Alejandro Hirmas

unread,
Jul 21, 2021, 7:33:33 AM7/21/21
to oTree help & discussion
Hi everyone!

I am trying to build a loop in oTree to iterate over some items with multiple attributes. Namely, I wanted to do:

{{ for slide in Constants.Slides }}
<div class="flex-container">

  <!-- Title -->
  <h1> {{ slide.Title }} </h1>

  <!-- Intro text -->
  <div class="slide-item">
    {{ include slide.path }}
  </div>
  <!-- Next button -->
  <button class="button intro-button">Next</button>
</div>
{{ endfor }}

Where:
    Slides = dict(
            slide1 = dict(Title = 'Slide1',path='Instructions/slide1.html'),
            slide2 = dict(Title = 'Slide2',path='Instructions/slide2.html')
        )

Sadly, it seems that I cannot do it this way as slide.Title and slide.Path is not recognized. 

Any ideas?

Best regards,
Alejandro

Chris @ oTree

unread,
Jul 21, 2021, 10:48:39 AM7/21/21
to Alejandro Hirmas, oTree help & discussion
Instead of a dict of dicts, use a list of dicts. 

Sent from my phone

On Jul 21, 2021, at 5:33 AM, Alejandro Hirmas <janoh...@gmail.com> wrote:

Hi everyone!
--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/d1248da8-9165-4746-96a1-3562fe4af4c8n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages