2

I have a setup where I have to parse information from a matrix field that is nested within a playa loop.

The template code would look like this:

{exp:channel:entries}

    {matrix_tag_pair}

            {playa}

                {matrix_field}

            {/playa}

    {/matrix_tag_pair}

{/exp:channel:entries}

Unfortunately the {matrix_field} would not parse. Any idea how to make the matrix field parse other than to place it outside the {playa} loop?

Cheers

Edit:

here is the longer version:

I would like to add a couple af products at the same time in a ct cart.

The products I add recide in a matrix that contains a playa field. The matrix is a recipe and the ingredients are the playa field that come from a product/ingredients channel. The quantity is defined with the matrix field {quantity}.

a basic example is this:

{exp:cartthrob:multi_add_to_cart_form return="/store/cart"}
{exp:channel:entries
    channel="recipes"
    disable="categories|category_fields|member_data|pagination|trackbacks"
}
        <ul>
            <li>{title}
                <ul>You will need:
                    {matrix_recipes}
                        <li>
                            {products}{!-- playa field --}
                                {title}
                                <input type="hidden" name="entry_id[{entry_id}]" value="{entry_id}" />
                                <input type="input" name="quantity[{entry_id}]" value="{quantity}" />
                                (price:{product_price} each)
                            {/products}

                        </li>                       
                    {/matrix_recipes}
                </ul>
            </li>
        </ul>       

<input type="submit" value="add to cart"/> 

{/exp:channel:entries}

    {/exp:cartthrob:multi_add_to_cart_form}

The problem with the above setup is that the quantity is not rendering. I found a couple of ways to make this work but they were all looking clumsy. One was to wrap playa fields in the playa tag pairs leaving the quantity field outside the playa loop. That left me with a far to verbose template code.

4
  • Can you provide a little context with regard to what you're trying to do? A Matrix field inside a Playa field, inside a Matrix field sounds uniquely deep. There may well be another way to do it.
    – Ian Young
    Apr 16, 2013 at 7:49
  • Hey Christian - have you tried the approach here? pixelandtonic.com/playa/docs/celltype It sounds fairly close to what you need.
    – Lisa
    Apr 16, 2013 at 16:21
  • Hi Lisa Thanks for pointing this out. However the new docs [link]docs.pixelandtonic.com/playa[/link] don't show this feature anymore (or is it just me not being able to find it)?
    – Christian
    May 7, 2013 at 14:24
  • I'm also running into this problem -- It seems like the embedded matrix fields don't loop.
    – Bryant
    Jul 15, 2013 at 18:14

1 Answer 1

1

Have you tried using Stash for this?

Maybe something like this would work:

{exp:channel:entries}
    {matrix_tag_pair}
        {exp:stash:set name="whatever_matrix_fields"}{matrix_field}{/exp:stash:set}
        {playa}
            {exp:stash:get name="whatever_matrix_fields"}
        {/playa}
    {/matrix_tag_pair}
{/exp:channel:entries}

Your Answer

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

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