Question

I am a new comer to CB and I'm working on a project in which I need to pass a list of the previous 12 months from today's date to the view, in the fashion of Year,Month, so that the view writes something as follows for each.

<div class="date">
      <h4>2103</h4>
      <div<JAN</div>
 </div>

I haven't been able to figure out a variable schema in order to properly reference the elements on the view.

Was it helpful?

Solution

This was answered elsewhere, so I am filling in for reference.

A list of lists do the job:

On Controller:

Dates = [ [{year, "2013"}, {month, "JAN"}], [{year, "2013"}, {month, "FEB"}] ],

and pass the var to the template: {dates, Dates}

On view:

{% for date in dates %}
    Year: {{ date.year }}<br>
    Month: {{ date.month }}<br>
{% endfor %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top