0

I need to display a tour itinerary which is put together in a Matrix field where the first column selects the day of the itinerary and another column is a Playa field that relates to entries in a variety of other channels. The image in the related field is an Assets field.

I've got everything to display OK how I want it which is similar to this:

Day 1
- Title / image
- Title / image
- Title / image
Day 2
- Title / image
- Title / image

but the way I have it at the moment adds about 100 queries and an extra second load time to the page.

So I'm after some advice on how to better optimise the below to reduce the queries.

Do I need to use the query module or can it all be done with Stash cacheing/nested lists?

{exp:stash:set_list
  name="days"
  parse_tags="yes"
  parse_depth="3"
  trim="yes"
  save="yes"
  refresh="1440"
  replace="no"
}
  {!-- Matrix --}
  {itinerary var_prefix="day"}

    {stash:number}{day:day}{/stash:number}

    {!-- Playa --}
    {day:place var_prefix="place"}

      {stash:place-title}{place:title}{/stash:place-title}

      {!-- This is ugly but it appears you can't do {channel_short_name}-images  --}
      {stash:place-image}
        {exp:switchee variable="{place:channel_short_name}" parse="inward"}
          {case value="place"}
            {place:place-images limit='1'}
              {!-- Snippet to output thumb with CE Image --}
            {/place:place-images}
          {/case}
          {case value="departure"}
            {place:departure-images limit='1'}
              {!-- Snippet to output thumb with CE Image --}
            {/place:departure-images}
          {/case}
        {/exp:switchee}
      {/stash:place-image}

      {/day:place}

  {/itinerary}
{/exp:stash:set_list}

{!-- Output – loop through days 1-30 and output matrix rows whose day equals the current count --}

{exp:low_list:each
  items="1|30"
  range="yes"
  parse="inward"
}

{exp:stash:get_list
  name="days"
  match="#^{val}$#"
  against="number"
  prefix="list"
}

  {list:place-title}
  {list:place-image}

{/exp:stash:get_list}
{/exp:low_list:each}
4
  • Purely out of curiosity, have you tried with native grid and relationships? Jul 26 '16 at 13:27
  • It's an existing site I've been brought in to help out on with lots of data already entered so that's not really an option.
    – Tyssen
    Jul 26 '16 at 21:22
  • Are you using native template caching? Aug 1 '16 at 19:40
  • No, not enough control over cache clearing with the native methods. FWIW, Mark Croxton pointed out that I needed scope="site" for the variable to be stored in the database.
    – Tyssen
    Aug 1 '16 at 21:40

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.