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.

有帮助吗?

解决方案

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 %}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top