cycle
Changed in Django 1.0: Cycle among the given strings or variables each time this tag is encountered.
Within a loop, cycles among the given strings each time through the loop:
{% for o in some_list %}
<tr class="{% cycle 'row1' 'row2' %}">
...
</tr>
{% endfor %}
You can use variables, too. For example, if you have two template variables, rowvalue1 and rowvalue2, you can cycle between their values like this:
{% for o in some_list %}
<tr class="{% cycle rowvalue1 rowvalue2 %}">
...
</tr>
{% endfor %}
Yes, you can mix variables and strings:
{% for o in some_list %}
<tr class="{% cycle 'row1' rowvalue2 'row3' %}">
...
</tr>
{% endfor %}
In some cases you might want to refer to the next value of a cycle from outside of a loop. To do this, just give the {% cycle %} tag a name, using "as", like this:
{% cycle 'row1' 'row2' as rowcolors %}
From then on, you can insert the current value of the cycle wherever you'd like in your template:
<tr class="{% cycle rowcolors %}">...</tr>
<tr class="{% cycle rowcolors %}">...</tr>
You can use any number of values in a {% cycle %} tag, separated by spaces. Values enclosed in single (') or double quotes (") are treated as string literals, while values without quotes are treated as template variables.
Note that the variables included in the cycle will not be escaped. This is because template tags do not escape their content. If you want to escape the variables in the cycle, you must do so explicitly:
{% filter force_escape %}
{% cycle var1 var2 var3 %}
{% endfilter %}
For backwards compatibility, the {% cycle %} tag supports the much inferior old syntax from previous Django versions. You shouldn't use this in any new projects, but for the sake of the people who are still using it, here's what it looks like:
{% cycle row1,row2,row3 %}
In this syntax, each value gets interpreted as a literal string, and there's no way to specify variable values. Or literal commas. Or spaces. Did we mention you shouldn't use this syntax in any new projects?
分享到:
相关推荐
Built-In Building Blocks.dotx office2016 .
Unity Built-in 到 URP 函数对应整理 Unity 的可编程渲染管线(Scriptable Render Pipeline)代表了 Unity 处理图形方式的一大进步,为用户提供了更多定制管线的能力。然而, Built-in 到 URP 的示例仍然较少,这...
Unity内置Shader,也被称为built-in-shaders,是Unity引擎的核心组成部分,用于实现各种图形效果。在Unity 2022.2.7f1版本中,这些Shader提供了丰富的功能,适用于游戏开发、虚拟现实(VR)、增强现实(AR)和其他...
Functions - Spark SQL, Built-in Functions,强大的sql全部语法。
**IMX185数据手册概述** IMX185是一款由索尼公司推出的高性能CMOS图像传感器,专门设计用于各种视觉应用,如工业自动化、医疗成像、无人机、监控摄像头等。这款传感器以其高分辨率、高动态范围以及内置WDR(宽动态...
苹果摄像头在win64系统下的驱动,苹果Apple Built-in iSight Drivers驱动。
The webMethods Integration Server Built-In Services Reference describes the built-in services provided with a standard installation of the webMethods Integration Server. Services are also installed ...
- build: built -> built - burn: burnt/burned -> burnt/burned - buy: bought -> bought - catch: caught -> caught - dig: dug -> dug - dream: dreamt/dreamed -> dreamt/dreamed - feed: fed -> fed - ...
标题 "Apple-Broadcom-Built-in-Bluetooth-6.0.6100.0.zip" 暗示我们正在处理一个与Apple公司和Broadcom公司合作开发的内置蓝牙驱动程序有关的软件包。这个版本号6.0.6100.0表示这是一个特定的更新或修复,可能包含...
在"Oracle-Built-In-Packages"这本书中,作者详细介绍了如何利用这些内置包来提升效率和性能。以下是书中的主要内容概览: **A. 伴侣光盘内容** 光盘中包含的资源可能是电子版的书籍、示例代码库或其他辅助学习...
Oracle Built-in Packages原文,可以当手册使用,2010年出版的。
### SpyGlass Built-In Rules Reference Guide知识点解析 #### 一、版权与使用许可声明 - **版权声明**:本文档为Synopsys, Inc.版权所有,并受著作权保护。未经Synopsys, Inc.书面许可协议,不得使用、复制、修改...
这类动词包括:bring -> brought -> brought, build -> built -> built, buy -> bought -> bought等。 - 但也有一些动词如get、hang(悬挂)和lay(放置)存在不规则变化:get -> got -> gotten, hang -> hung -> ...
Customizable Rocks And Stones Stylized URP Built-In v1.1
Hologram Shaders Pro for URP HDRP Built-in
Easy Performant Outline 2D 3D URP HDRP and Built-in Renderer 3.3
一种通信装备Built-In Test技术研究与实现.caj