• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Template Based For Loop?

Jaxel

Well-known member
#1
Currently in one of my templates I am doing the following:
Code:
<select name="month" class="textCtrl autoSize">
	<option value="1" <xen:if is="{$month} == 1">selected</xen:if>>{xen:phrase month_1}</option>
	<option value="2" <xen:if is="{$month} == 2">selected</xen:if>>{xen:phrase month_2}</option>
	<option value="3" <xen:if is="{$month} == 3">selected</xen:if>>{xen:phrase month_3}</option>
	<option value="4" <xen:if is="{$month} == 4">selected</xen:if>>{xen:phrase month_4}</option>
	<option value="5" <xen:if is="{$month} == 5">selected</xen:if>>{xen:phrase month_5}</option>
	<option value="6" <xen:if is="{$month} == 6">selected</xen:if>>{xen:phrase month_6}</option>
	<option value="7" <xen:if is="{$month} == 7">selected</xen:if>>{xen:phrase month_7}</option>
	<option value="8" <xen:if is="{$month} == 8">selected</xen:if>>{xen:phrase month_8}</option>
	<option value="9" <xen:if is="{$month} == 9">selected</xen:if>>{xen:phrase month_9}</option>
	<option value="10" <xen:if is="{$month} == 10">selected</xen:if>>{xen:phrase month_10}</option>
	<option value="11" <xen:if is="{$month} == 11">selected</xen:if>>{xen:phrase month_11}</option>
	<option value="12" <xen:if is="{$month} == 12">selected</xen:if>>{xen:phrase month_12}</option>
</select>
I know there is a foreach loop, but is there a built in basic for loop? I want to do something like:
Code:
<select name="month" class="textCtrl autoSize">
	<xen:for i="1" stop="12" step="1">
		<option value="{$i}" <xen:if is="{$month} == {$i}">selected</xen:if>>{xen:phrase month_$i}</option>
	</xen:for>
</select>
Also... can I do {xen:phrase month_$1} ?
 

Luke F

Well-known member
#3
Setting a template variable using the output of range(1,12) in your controller code and then using a foreach loop over that seems to be about as close as you can get to a for loop currently.