#34468 closed Bug (invalid)

`Cycle` tag do not work with variables defined in `with`-tag.

Reported by: Алексей Поклонский Owned by: nobody
Component: Template system Version: 4.0
Severity: Normal Keywords: cycle, with, templates
Cc: jispar@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Here is the example:

{# context is simple dict with one key {A=["1", "2", "3"]} #}

{% with example_defined_variable="123" %}

{% for item in A %}

Current item: {{ item }}

Current cycle item: {% cycle example_defined_variable %}

{% endfor %}

Visible page.

{% endwith %}

As you can see I render this template using django 4.0.1 and context containing 1 key "A" with the value of ["1", "2", "3"] (that is the list of strings).
Then I try to print the items of the list along with predefined value (see with-tag).
The result must be like:

Current item: 1 
Current cycle item: 123 
Current item: 2 
Current cycle item: 123 
Current item: 3 
Current cycle item: 123 
Visible page.

But instead Im getting:

No named cycles in template. 'example_defined_variable' is not defined

That means that cycle-tag do not recognize example_defined_variable as defined variable, BUT
on the documentation page there is the note that you CAN use defined variables in cycle-tag.

Change History (1)

comment:1 by Mariusz Felisiak, 20 months ago

Resolution: invalid
Status: newclosed

When a single argument is passed to the {% cycle %} it has to be a named cycle because it doesn't make a lot of sense to cycle among the single value.

{% with %} works properly with {% cycle %}, for example:

{% with example_defined_variable="123" %}
{% with example_defined_variable2="123" %}
Current cycle item: {% cycle example_defined_variable example_defined_variable2 %}
Note: See TracTickets for help on using tickets.
Back to Top