2

I have a product section. When I create a product entry, I select related product entries via a Playa field. I can get this to display as expected.

I have now added a matrix field on the product entry page that allows me to upload multiple product images for a specific entry.

When I view a product entry on the front end, the related products display as expected except for the images. All related products show the image from the main entry page they are currently visiting. Not the image for the entry that is related.

So I end up with a number of related products all sharing the same image.

I'm not sure where to go from here. Any help would be greatly appreciated.

Here's the code

{exp:channel:entries channel="products"}
                            {related_products} <!--THIS IS THE PLAYA FIELD FOR RELATED PRODUCTS-->
                                <div class="col-md-12">
                                    <div class="item product">
                                        <div class="product-thumb-info">

                                            <div class="product-thumb-info-image">
                                                <span class="product-thumb-info-act">
                                                    <a href="{exp:transcribe:uri path="paint/product/{url_title}"}" title="{title}" class="view-product">
                                                        <span><i class="fa fa-external-link"></i></span>
                                                    </a>
                                                </span>
                                                <a href="{exp:transcribe:uri path="paint/product/{url_title}"}">
                                                    {product_image limit="1"} <!--THIS IS THE MATRIX FIELD FOR THE IMAGES-->
                                                        <img alt="{title}" title="{title}" class="img-responsive" src="{main_product_image}">
                                                    {/product_image}
                                                </a>
                                            </div>

                                            <div class="product-thumb-info-content">
                                                <span class="price pull-right">{sizes_available}</span>
                                                <h4><a href="{exp:transcribe:uri path="paint/product/{url_title}"}">{title}</a></h4>
                                                <span class="item-cat"><small><a href="{exp:transcribe:uri path="paint/product/{url_title}"}">{paint_type}</a></small></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            {/related_products}
                        {/exp:channel:entries}
1

It might be a namespacing issue for the matrix field, and it's outputting the main_product_image variable from the product page, not the related products. You can add a var_prefix parameter to the matrix tag and the prefix to each matrix variable:

{product_image limit="1" var_prefix="mx"} <!--THIS IS THE MATRIX FIELD FOR THE IMAGES-->
    <img alt="{title}" title="{title}" class="img-responsive" src="{mx:main_product_image}">
{/product_image}

UPDATE: Here's a test version with namespacing for playa and matrix:

{exp:channel:entries channel="products"}
    Entry Title: {title}<br>

    {!--playa--}
    {related_products
        var_prefix="pl"
    }
        Related Title: {pl:title}<br>

        {!--matrix--}
        {pl:product_image 
            limit="1"
            var_prefix="mx"
        }
            Related Title within Matrix: {pl:title}<br>
            Related Image within Matrix: {mx:main_product_image}<br>
        {/pl:product_image}


        {!--link for related product--}
        <a href="{exp:transcribe:uri path='paint/product/{pl:url_title}'}">{pl:title}</a>

    {/related_products}

    <hr>
{/exp:channel:entries}
| improve this answer | |
  • Thanks for taking the time to make a suggestion. Sadly, it's doing the exact same thing. Very strange. As soon as I added the mx:title to the title attribute it wouldn't display the title it just showed the variable. Not sure if that gives any additional information. The images still continue to be the images from the main product image. – Mark Dodgson Oct 9 '14 at 15:13
  • I'll try to update the answer in a few. I put it up too quickly maybe :) – Romans-8---31-39 Oct 9 '14 at 17:36
  • 1
    Check the updated version and see if you get the right output for the variables? – Romans-8---31-39 Oct 9 '14 at 18:05
  • Hey Romans-8---31-39, I'm so sorry for the delay. Thank You for your help. You totally fixed the issue I was having, but it's created another issue that I'll need to sort out. The transcribe URL is now adding a hash at the end of the template paths which breaks the links to the products. Have you had any experience with Transcribe? – Mark Dodgson Oct 15 '14 at 14:59
  • 1
    You were referencing the url_title like {url_title} which points to the page entry. Adding the playa prefix points to the related url_title: {pl:url_title}. (see the update) – Romans-8---31-39 Oct 15 '14 at 15:37

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.