1

So I have a system that needs to display some data depending on whether the date of an event falls within a number of preset dates. It's working great right now but there is this one part that is just bugging me. I feel like I could achieve this much more economically but that's where my knowledge runs out.

Here is an example of what I have:

{exp:channel:entries channel="term_dates" entry_id="236" limit="1" dynamic="no" disable="categories|pagination|trackbacks" parse="inward"}
{exp:stash:set_list name="term_dates"}
        {term_dates}
            {stash:date}{term_dates:date format="%U"}{/stash:date}
            {stash:term}{term_dates:term}{/stash:term}
        {/term_dates}
    {/exp:stash:set_list}       
{/exp:channel:entries}

.

{exp:stash:get_list name="term_dates" limit="1"  offset="0" prefix="term"}{exp:stash:set parse_tags="yes" name="date01"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term01"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1"  offset="1" prefix="term"}{exp:stash:set parse_tags="yes" name="date02"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term02"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1"  offset="2" prefix="term"}{exp:stash:set parse_tags="yes" name="date03"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term03"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1"  offset="3" prefix="term"}{exp:stash:set parse_tags="yes" name="date04"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term04"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1"  offset="4" prefix="term"}{exp:stash:set parse_tags="yes" name="date05"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term05"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1"  offset="5" prefix="term"}{exp:stash:set parse_tags="yes" name="date06"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term06"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1"  offset="6" prefix="term"}{exp:stash:set parse_tags="yes" name="date07"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term07"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1"  offset="7" prefix="term"}{exp:stash:set parse_tags="yes" name="date08"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term08"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1"  offset="8" prefix="term"}{exp:stash:set parse_tags="yes" name="date09"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term09"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1"  offset="9" prefix="term"}{exp:stash:set parse_tags="yes" name="date10"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term10"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="10" prefix="term"}{exp:stash:set parse_tags="yes" name="date11"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term11"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="11" prefix="term"}{exp:stash:set parse_tags="yes" name="date12"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term12"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="12" prefix="term"}{exp:stash:set parse_tags="yes" name="date13"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term13"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="13" prefix="term"}{exp:stash:set parse_tags="yes" name="date14"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term14"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="14" prefix="term"}{exp:stash:set parse_tags="yes" name="date15"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term15"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="15" prefix="term"}{exp:stash:set parse_tags="yes" name="date16"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term16"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="16" prefix="term"}{exp:stash:set parse_tags="yes" name="date17"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term17"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="17" prefix="term"}{exp:stash:set parse_tags="yes" name="date18"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term18"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="18" prefix="term"}{exp:stash:set parse_tags="yes" name="date19"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term19"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="19" prefix="term"}{exp:stash:set parse_tags="yes" name="date20"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term20"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="20" prefix="term"}{exp:stash:set parse_tags="yes" name="date21"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term21"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="21" prefix="term"}{exp:stash:set parse_tags="yes" name="date22"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term22"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="22" prefix="term"}{exp:stash:set parse_tags="yes" name="date23"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term23"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="23" prefix="term"}{exp:stash:set parse_tags="yes" name="date24"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term24"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="24" prefix="term"}{exp:stash:set parse_tags="yes" name="date25"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term25"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="25" prefix="term"}{exp:stash:set parse_tags="yes" name="date26"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term26"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="26" prefix="term"}{exp:stash:set parse_tags="yes" name="date27"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term27"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="27" prefix="term"}{exp:stash:set parse_tags="yes" name="date28"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term28"}{term:term}{/exp:stash:set}{/exp:stash:get_list}
{exp:stash:get_list name="term_dates" limit="1" offset="28" prefix="term"}{exp:stash:set parse_tags="yes" name="date29"}{term:date}{/exp:stash:set}{exp:stash:set parse_tags="yes" name="term29"}{term:term}{/exp:stash:set}{/exp:stash:get_list}


{exp:stash:get_list name="enq_view"}

{exp:stash:set trim="yes" parse_tags="yes" parse_conditionals="yes"}
{stash:term_time}
{if '{en_date_check}' > '{exp:stash:date01}' AND '{en_date_check}' < '{exp:stash:date02}'}{exp:stash:term01}{/if}
{if '{en_date_check}' > '{exp:stash:date02}' AND '{en_date_check}' < '{exp:stash:date03}'}{exp:stash:term02}{/if}
{if '{en_date_check}' > '{exp:stash:date03}' AND '{en_date_check}' < '{exp:stash:date04}'}{exp:stash:term03}{/if}
{if '{en_date_check}' > '{exp:stash:date04}' AND '{en_date_check}' < '{exp:stash:date05}'}{exp:stash:term04}{/if}
{if '{en_date_check}' > '{exp:stash:date05}' AND '{en_date_check}' < '{exp:stash:date06}'}{exp:stash:term05}{/if}
{if '{en_date_check}' > '{exp:stash:date06}' AND '{en_date_check}' < '{exp:stash:date07}'}{exp:stash:term06}{/if}
{if '{en_date_check}' > '{exp:stash:date07}' AND '{en_date_check}' < '{exp:stash:date08}'}{exp:stash:term07}{/if}
{if '{en_date_check}' > '{exp:stash:date08}' AND '{en_date_check}' < '{exp:stash:date09}'}{exp:stash:term08}{/if}
{if '{en_date_check}' > '{exp:stash:date09}' AND '{en_date_check}' < '{exp:stash:date10}'}{exp:stash:term09}{/if}
{if '{en_date_check}' > '{exp:stash:date10}' AND '{en_date_check}' < '{exp:stash:date11}'}{exp:stash:term10}{/if}
{if '{en_date_check}' > '{exp:stash:date11}' AND '{en_date_check}' < '{exp:stash:date12}'}{exp:stash:term11}{/if}
{if '{en_date_check}' > '{exp:stash:date12}' AND '{en_date_check}' < '{exp:stash:date13}'}{exp:stash:term12}{/if}
{if '{en_date_check}' > '{exp:stash:date13}' AND '{en_date_check}' < '{exp:stash:date14}'}{exp:stash:term13}{/if}
{if '{en_date_check}' > '{exp:stash:date14}' AND '{en_date_check}' < '{exp:stash:date15}'}{exp:stash:term14}{/if}
{if '{en_date_check}' > '{exp:stash:date15}' AND '{en_date_check}' < '{exp:stash:date16}'}{exp:stash:term15}{/if}
{if '{en_date_check}' > '{exp:stash:date16}' AND '{en_date_check}' < '{exp:stash:date17}'}{exp:stash:term16}{/if}
{if '{en_date_check}' > '{exp:stash:date17}' AND '{en_date_check}' < '{exp:stash:date18}'}{exp:stash:term17}{/if}
{if '{en_date_check}' > '{exp:stash:date18}' AND '{en_date_check}' < '{exp:stash:date19}'}{exp:stash:term18}{/if}
{if '{en_date_check}' > '{exp:stash:date19}' AND '{en_date_check}' < '{exp:stash:date20}'}{exp:stash:term19}{/if}
{if '{en_date_check}' > '{exp:stash:date20}' AND '{en_date_check}' < '{exp:stash:date21}'}{exp:stash:term20}{/if}
{if '{en_date_check}' > '{exp:stash:date21}' AND '{en_date_check}' < '{exp:stash:date22}'}{exp:stash:term21}{/if}
{if '{en_date_check}' > '{exp:stash:date22}' AND '{en_date_check}' < '{exp:stash:date23}'}{exp:stash:term22}{/if}
{if '{en_date_check}' > '{exp:stash:date23}' AND '{en_date_check}' < '{exp:stash:date24}'}{exp:stash:term23}{/if}
{if '{en_date_check}' > '{exp:stash:date24}' AND '{en_date_check}' < '{exp:stash:date25}'}{exp:stash:term24}{/if}
{if '{en_date_check}' > '{exp:stash:date25}' AND '{en_date_check}' < '{exp:stash:date26}'}{exp:stash:term25}{/if}
{if '{en_date_check}' > '{exp:stash:date26}' AND '{en_date_check}' < '{exp:stash:date27}'}{exp:stash:term26}{/if}
{if '{en_date_check}' > '{exp:stash:date27}' AND '{en_date_check}' < '{exp:stash:date28}'}{exp:stash:term27}{/if}
{if '{en_date_check}' > '{exp:stash:date28}' AND '{en_date_check}' < '{exp:stash:date29}'}{exp:stash:term28}{/if}
{if '{en_date_check}' > '{exp:stash:date29}'}{exp:stash:term29}{/if}
{/stash:term_time}
{/exp:stash:set}

all this to give me a word:

{exp:stash:term_time}

and to top it off all of this is within another loop and is checked on each iteration.

Not very elegant. It isn't causing any noticeable performance issues (surprisingly) but it just doesn't seem ideal at all.

any ideas?

Is there another way to achieve this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.