CartThrob 9 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

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

  1. This is a looping tag pair; output comes from the tag body.
  2. Range is generated from start_year to start_year + years - 1.
  3. Year values are returned in ascending order.
  4. If years is 0 (or negative), no rows are returned.
  5. 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}