Years
years is a tag pair that outputs a loopable list of year values.
Use this when you want full template control over markup. If you want CartThrob to output the complete <select> for you, use year_select.
See also:
Parameters
years
How many years to return.
Default: 5.
If non-numeric, CartThrob falls back to 5.
years="5"
start_year
First year in the returned range.
Default: current year (date('Y')).
If non-numeric, CartThrob falls back to the current year.
start_year="2026"
Variables
year
Current year value for each loop row.
{year}
Behavior and Constraints
- This is a looping tag pair; output comes from the tag body.
- Range is generated from
start_yeartostart_year + years - 1. - Year values are returned in ascending order.
- If
yearsis0(or negative), no rows are returned. - This tag only outputs year values; it does not render a
<select>on its own.
Examples
Standard expiration-year style list:
<select name="expiration_year">
{exp:cartthrob:years years="6"}
<option value="{year}">{year}</option>
{/exp:cartthrob:years}
</select>
Custom range start:
{exp:cartthrob:years start_year="2030" years="3"}
{year}<br>
{/exp:cartthrob:years}
Current year forward (defaults):
{exp:cartthrob:years}
{year}
{/exp:cartthrob:years}