2

Under my basket page (based on the sample 'checkout.html) I want to suggest any accessories that might be associated with the products in the basket.

I've tried two ways to achieve this, neither is really working for me at the moment. My first attempt was to use PHP to capture the {entry_id} of each item in the first loop and then use that below. Problem I encountered is that I need PHP to be rendered both on InPut and Output on the template (one to capture the id's, the other to make using them possible).

My second attempt is just to have a second {items} loop under the first. Within this loop I try to get the exp:channel:entries with the {entry_id} of each item then within the exp:channel:entries loop get the related_entries (there are 4).

This logic seems sound to me, but I am new to expression engine and store so I am sure I am missing something obvious!

My code is below, any help you can offer is very much appreciated.

<h2>Suggested Accessories / Related Products</h2>

{items}
    {exp:channel:entries limit="1" dynamic="off" entry_id="{entry_id}" }
        {related_entries id="related_product_1"}
            A {title} - {entry_id}
        {/related_entries}<br/>
        {related_entries id="related_product_2"}
            B {title} - {entry_id}
        {/related_entries}<br/>
        {related_entries id="related_product_3"}
            C {title} - {entry_id}
        {/related_entries}<br/>
        {related_entries id="related_product_4"}
            D {title} - {entry_id}
        {/related_entries}

    {/exp:channel:entries}  
{/items}
3

It's probably a parsing issue. Try an embed.

In your main template set:

{items}
    {embed="embeds/related" id="{entry_id}"}
{/items}

Then create a new template called "related" in an "embeds" template group (or use your own naming). In that template set:

{exp:channel:entries limit="1" dynamic="off" entry_id="{embed:id}" }
    {related_entries id="related_product_1"}
        A {title} - {entry_id}
    {/related_entries}<br/>
    {related_entries id="related_product_2"}
        B {title} - {entry_id}
    {/related_entries}<br/>
    {related_entries id="related_product_3"}
        C {title} - {entry_id}
    {/related_entries}<br/>
    {related_entries id="related_product_4"}
        D {title} - {entry_id}
    {/related_entries}

{/exp:channel:entries}  

If the {entry_id} in your related loop needs to be the one you are passing to the embed, then change to {embed:id}.

| improve this answer | |
  • That is just the ticket. Thank you Anna! Useful to know that splitting the code segments into templates can have that effect. – Tomtids Feb 8 '13 at 11:05

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.