Say I want to print out the numbers 0 to 4 on an HTML page. How would I change the following code to do it:
<ul> {%for i in range(5) %} <li><a>i</a></li> {%endfor %} </ul> If you have a serverside language, say, PHP:
<ul> <?php for ($i = 0; $i < 5; $i++): ?> <li><a><?=$i?></a></li> <?php endfor; ?> </ul> Or, Django:
<ul> {% for i in 5|get_range %} <li>{{ i }}</li> {% endfor %} </ul> Otherwise, you'll need to do it after the page loaded, with javascript, here's a jsfiddle.
<ul id="dynamicList"></ul> <script type="text/javascript"> (function() { var list = document.getElementById('dynamicList'); for (var i = 0; i < 5; i++) { var li = document.createElement('li'); li.innerHTML = i; list.appendChild(li); } })(); </script>
iis just a plaintexti. If you want it to be treated as your loop variable, you'll have to mark it as a variable - otherwise theiin<li>would also become<l1>,<l2>etc...