If I have a matrix field with data like

Mon    X    Y
Mon    A    B
Tue    X    Y
Wed    X    Y
Wed    A    B

how can I output that on the front-end so that it looks like

Mon    Tue    Wed    
X Y    X Y    X Y
A B           A B

At the moment I'm getting

Mon    Mon    Tue    Wed    Wed    
X Y    A B    X Y    X Y    A B
  • I guess it would be easiest done with css, something like div.day[Mon]:nth-child(n+1) { display:none; } Mar 1, 2017 at 6:52
  • I've updated the desired output. I'm not sure I can achieve that with CSS.
    – Tyssen
    Mar 1, 2017 at 10:59

1 Answer 1


Sounds like a good use for stash. Capture the matrix (or the entire entry, it's up to you). The following assumes you know how to capure and set a list with stash, ie:

{exp:stash:set_list name="matrix_block"}         
<!-- Capture the matrix to a list -->
        {stash:day}{day}{/stash:day} <!-- The day -->
        {stash:col_1}{event_1}{/stash:col_1} <!-- Value 1 -->

<!-- Now we have a list, duplicate it and create new list using only the days -->

<!-- Now out put the sucker -->
{exp:stash:parse} <!-- Make sure everything else is set before trying to target data -->

{exp:stash:get_list name="daysofweek" unique="day" require_prefix="yes" prefix="out" } <!-- 
    Get the days from our duplicated list, using unique="" makes sure we dont get duplicate days,
    force prefix so inner get_list doesn't bork -->

    <li>{out:day} <!-- The unique day -->

        {exp:stash:get_list:sub name="matrix_block" match="#^{out:day}$#" against="day" parse="inward" }<!--
            Get the full list, match the contents 'day' against the day in this list -->

                <li>{col_1} {col_2}</li>



Mae sure your Stash is up-to-date. Tested locally with hard coded list and works fine.

Update: stash:get_list:sub is used when you're inside a get_list already. I used sub but could be elephant.

'raw' refers to the initial set_list name, updated code I mistakenly used raw instead of matrix_block

  • The headings are coming out OK but I'm not getting any of the other data. I've never come across the exp:stash:get_list:sub tag before. Is it documented anywhere? And what does the name raw refer to?
    – Tyssen
    Mar 3, 2017 at 5:28
  • Answer updated. Mar 3, 2017 at 7:59
  • Needed a prefix on the sub list but all good now, thanks :)
    – Tyssen
    Mar 6, 2017 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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