1

I have a matrix field which outputs a series of prices for a tour. An image probably illustrates most easily what I'm doing and need to do.

Table above as it is now; table below as it should be

Where the ticket title is repeated in subsequent rows, it needs to be hidden and also a rowspan applied so the number of rows with the same ticket title would need to be counted.

Same with the type in the 2nd column. And they also need to be grouped by background-color.

{exp:stash:set_list
  context="@URI"
  name="prices"
  parse_tags="yes"
  parse_depth="1"
  trim="yes"
  save="yes"
  refresh="1440"
  replace="no"
  scope="site"
}
  {tour-tickets}

    {stash:type}{tour-ticket-accomm-type}{/stash:type}
    {stash:min}{tour-ticket-accomm-min-pax}{/stash:min}
    {stash:max}{tour-ticket-accomm-capacity}{/stash:max}
    {stash:title}{tour-ticket-title}{/stash:title}
    {stash:price}{tour-ticket-price}{/stash:price}
    {stash:special}{tour-ticket-price-special}{/stash:special}
    {stash:peak}{tour-ticket-price-peak}{/stash:peak}
    {stash:special-peak}{tour-ticket-price-special-peak}{/stash:special-peak}
    {stash:details}{tour-ticket-details}{/stash:details}

  {/tour-tickets}
{/exp:stash:set_list}

<table>
  <thead>
    <tr>
      <th scope="col">Ticket</th>
      <th scope="col">Type</th>
      <th scope="col">Details</th>
      <th scope="col">Price</th>
    </tr>
  </thead>
  <tbody>
    {exp:stash:get_list
      name="prices"
      context="@URI"
      orderby="title|price|special|details|type"
      prefix="price"
    }
      <tr>
        <td>{price:title}</td>
        <td>{price:type} <br>(Min booking: {price:min}, Sleeps: {price:max})</td>
        <td>{price:details}</td>
        <td>{price:peak}</td>
      </tr>
    {/exp:stash:get_list}

  </tbody>
</table>

This is what I have so far as shown in the first table. Anyone have any ideas about how to achieve the presentation in the 2nd table?

2
  • Visually couldn't you just add a visibility:hidden to any repeated ticket titles? it'd still be there in the html, but wouldn't display.
    – CreateSean
    Aug 1 '16 at 16:37
  • But it's working out when a title is a repeat of something in a previous row which is the part I'm struggling with.
    – Tyssen
    Aug 1 '16 at 21:35
1

This will get you part of the way. It should be possible to group the type column as well, using the same principle, but you'd need an index column in the set list that combined the ticket value and the type value to match against (see https://github.com/croxton/Stash/wiki/Filtering%20lists%20with%20match%20against)

<table border="1">
  <thead>
    <tr>
      <th scope="col">Ticket</th>
      <th scope="col">Type</th>
      <th scope="col">Details</th>
      <th scope="col">Price</th>
    </tr>
  </thead>
  <tbody>
    {exp:stash:get_list
      name="prices"
      orderby="title|price|special|details|type"
      prefix="price"
      unique="title"
    }
      <tr>
        <td rowspan="{exp:stash:list_count name='prices' match='#^\Q{price:title}\E$#' against='title'}">{price:title}</td>

        {exp:stash:get_list:nested
          name="prices"
          orderby="title|price|special|details|type"
          prefix="nested"
          match="#^\Q{price:title}\E$#"
          against="title"
        }
            <td>{nested:type} <br>(Min booking: {nested:min}, Sleeps: {nested:max})  {exp:stash:list_count name="prices" match="#^\Q{price:title}\E$#" against="title"
        }</td>
            <td>{nested:details}</td>
            <td>{nested:price}</td>
        </tr>

        {/exp:stash:get_list:nested}

    {/exp:stash:get_list}

  </tbody>
</table>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.