3

I just updated to 2.7.2 and I'm trying to rework all of the relationship tags (the updater failed to convert them automatically as promised).

So I've got three channels: Author, Publisher, and Book. A book has two relationship fields, one for author (writer) and one for publisher that link to the other two channels respectively. When I display the the author listing, I need to display all related books. This is doing exactly what I want.

        {parents field="writer_rel"}

        <ul id="books">
            <li><h4><a href="{parents:url_title_path='book'}">{parents:title}</a></h4>
                <ul>

                    {if parents:publication_date}<li><strong>Publish Date: </strong>{parents:publication_date}</li>{/if}
                    {if parents:format}<li><strong>Type: </strong>{parents:format}</li>{/if}
                    {if parents:isbn_hardback}<li><strong>Hardback ISBN: </strong>{parents:isbn_hardback}</li>{/if}
                    {if parents:hb_pages}<li><strong>Pages:</strong>{parents:hb_pages}</li>{/if}
                    {if parents:isbn_paperback}<li><strong>Paperback ISBN: </strong>{parents:isbn_paperback}</li>{/if}
                    {if parents:pb_pages}<li><strong>Pages:</strong>{parents:pb_pages}</li>{/if}
                    {if parents:leo_call_number}<li><strong>Leo Call Number: </strong>{parents:leo_call_number}</li>{/if}

                </ul>

            </li>   
        </ul>

        {/parents}

So far, so good, but when I add the Publisher to the list, which is the second relationship field, things stop working. If I treat it just like any other field and add

{if parents:publisher_rel}<li><strong>Publisher: </strong>{parents:publisher_rel}</li>{/if}

It actually prevents the entire parents tag from being parsed. So I get this rendered on the page.

enter image description here

If I try to treat it like it's own independent parent tag like so:

                        {parents field="publisher_rel"}
                        {parents:title}
                    {/parents}

It just doesn't render. Weirdly, when nested inside the original parents tag it also prevents any further looping, so it doesn't display anything after the first entry.

So, yeah. I'm stuck. Any advice? Thanks very much.

  • 1
    What fieldtype is the publisher field? – Stephen Callender Nov 12 '13 at 15:01
2

You are actually trying to access the child ("Publisher") of a parent ("Book") - because you're currently viewing another child of the "Book" ("Author"). So that's why {parents field="publisher_rel"} won't work.

This code you posted should work, with one tweak - you need to add the field you want to display (in this case, :title):

{parents field="writer_rel"}
    {if parents:publisher_rel}<li><strong>Publisher: </strong>{parents:publisher_rel:title}</li>{/if}
{/parents}

This should also work (using a tag pair):

{parents field="writer_rel"}
    {parents:publisher_rel}<li><strong>Publisher: </strong>{parents:publisher_rel:title}</li>{/parents:publisher_rel}
{/parents}
| improve this answer | |
  • First, thanks for responding. FWIW, the first set of you code you posted did NOT work. It behaves just like my code did. The second chunk of code you posted both works AND makes sense to me, so thanks very much (I don't have enough rep to upvote your answer I'm afraid). – grovberg Nov 21 '13 at 18:11
2

What I ended up using was a siblings tag, which I somehow missed when I initially posted this.

{siblings field="publisher_rel"}
    {if siblings:title}<li><strong>Publisher: </strong>{siblings:title}{/if}
{/siblings}
| improve this answer | |

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.