0

This should be easy, but, I haven't been able to find an example anywhere.

I need to display {example_matrix_a} and {example_matrix_b} (both of which contain columns with the same names) via a Stash embed. I've tried the following, but, the Matrix fields aren't parsing. What step am I missing?

templates/default_site/example.group/layout_example.html:

{embed="wrappers/_interior"}

{exp:channel:entries limit="1"}
    {exp:stash:set name='title'}{title}{/exp:stash:set}
    {exp:stash:set name='maincontent'}
      {stash:embed:matrix_markup
        stash:matrix_field = "{example_matrix_a}"
        process="start"
      }
      {stash:embed:matrix_markup
        stash:matrix_field = "{example_matrix_b}"
        process="start"
      }

  {/exp:stash:set}
{/exp:channel:entries}

stash_templates/matrix_markup.html

{stash:matrix_field} 
   {matrix_col_1} - {matrix_col_2}<br>
{/stash:matrix_field} 
1

First, check this out: https://github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Aset_list%7D#capturing-and-caching-playa--matrix-tag-pairs

Second, unless you're reusing the matrix_markup Stash template, just keep it all together.

templates/default_site/example.group/layout_example.html:

{exp:channel:entries ...}
    {exp:stash:set_list name="matrix_a" parse_tags="yes" save="yes" scope="site"}
        {example_matrix_a}
            {stash:item_title}{title}{/stash:item_title}
            {!-- new stash tags for your columns --}
        {/example_matrix_a}
    {/exp:stash:set_list}

    {exp:stash:set name="title"}{title}{/exp:stash:set}
{/exp:channel:entries}

If, however, you are reusing the matrix_markup template, then you can do this.

templates/default_site/example.group/layout_example.html:

{exp:channel:entries ...}
    {exp:stash:set_list name="matrix_a" parse_tags="yes" save="yes" scope="site"}
        {stash:embed:partials:matrix_markup process="both"} {!-- or process="end" --}
    {/exp:stash:set_list}

    {exp:stash:set name="title"}{title}{/exp:stash:set}
{/exp:channel:entries}

stash_templates/partials/matrix_markup.html ← NOTE THE ADDITION OF THE 'PARTIALS' DIRECTORY

{example_matrix_a}
  {stash:item_title}{title}{/stash:item_title}
  {!-- new stash tags for your columns --}
{/example_matrix_a}

The Stash embed is assuming you have your config setup properly.

1

Here's another solution, per suggestions via Twitter by Stash's author:

templates/default_site/example.group/layout_example.html:

{embed="wrappers/_interior"}

{exp:channel:entries limit="1"}
    {exp:stash:set name='title'}{title}{/exp:stash:set}
    {exp:stash:set name='maincontent'}
      {stash:embed:matrix_markup
        stash:matrix_field = "example_matrix_a"
        process="start"
      }
      {stash:embed:matrix_markup
        stash:matrix_field = "example_matrix_b"
        process="start"
      }

  {/exp:stash:set}
{/exp:channel:entries}

stash_templates/matrix_markup.html

{{stash:matrix_field}} 
   {matrix_col_1} - {matrix_col_2}<br>
{/{stash:matrix_field}} 

This method (passing the name of the variable) works with Playa as well, and, I'd guess with just about any other field type that uses tag pairs.

1

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.