ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

playa relationship help please

November 29, 2011 11:04am

Subscribe [3]
  • #1 / Nov 29, 2011 11:04am

    Below I’ve got the following code working. it outputs the image and then the title of the parent entry via playa.

    <article id="content">
     {exp:channel:entries channel="clients" limit="500" disable="member_data|pagination|comments|categories"}
      {client-logo}
      
      {exp:playa:parents channel="testimonial"}
       {title}
      {/exp:playa:parents}
    
     {/exp:channel:entries}
    </article>

    What I want to do is wrap the image tag abouve with a tags that return to the parent entries single page, but only if that relationship exists i.e.

    <a href="/clients/testimonials/{url_title}">{client-logo}</a>

    Not sure how to do that and would really appreciate advice.

  • #2 / Nov 29, 2011 11:25am

    e-man

    1816 posts

    Check the playa docs: http://pixelandtonic.com/playa/docs/templates and specifically scan for conditional variables.
    There are quite a few available. You could for exanple use something like:

    {if no_parents}
    output image tag
    {if:else}
    output image tag wrapped with link to parent entry
    {/if}
  • #3 / Nov 29, 2011 11:37am

    Erwin,

    When I tried this:

    {exp:channel:entries channel="clients" limit="500" disable="member_data|pagination|comments|categories"}
     {if count =="1"}<ul>{/if}
     <li>
      {exp:playa:parents channel="testimonial"}
      {if no_parents}
       {client-logo}
      {if:else}
       <a href="/clients/testimonials/{url_title}">{client-logo}</a>
      {/if}
      {/exp:playa:parents}
     </li>
     {if count == total_results}</ul>{/if}
    {/exp:channel:entries}

    It output an unordered list without any images inside, which is perplexing as it seems like it should work.

  • #4 / Nov 29, 2011 11:42am

    jelle

    104 posts

    did you try parse=“inward” or dynamic=“no”?

  • #5 / Nov 29, 2011 11:49am

    update - I added another client this time without a relationship and now the template is giving me parse errors so I suspect there is something wrong with the conditional.

    now using the following:

    {exp:channel:entries channel="clients" limit="500" disable="member_data|pagination|comments|categories"}
     {if count =="1"}<ul>{/if}
     <li>
      {!--{client-logo}--}
      {exp:playa:parents channel="testimonial"}
      {if no_parents}
       {client-logo}
      {/if}
      {if parents}
       <a href="/clients/testimonials/{url_title}">{client-logo}</a>
      {/if}
      {/exp:playa:parents}
     </li>
     {if count == total_results}</ul>{/if}
    {/exp:channel:entries}

    Which outputs a list where the one entry that doesn’t have a relationship shows up an image tag but the custom field isn’t being output. Though if I use that custom field outide of the play tags it works just fine

  • #6 / Nov 29, 2011 12:20pm

    e-man

    1816 posts

    Not sure if {if parents} will work. Which custom field from which channel isn’t being rendered?

  • #7 / Nov 29, 2011 1:06pm

    Erwin,

    The {client-logo} field isn’t rendering and it’s in the clients channel.

  • #8 / Nov 29, 2011 4:46pm

    After some more experimentation I found the solution

    {exp:channel:entries channel="clients" limit="500" orderby="title" sort="asc" disable="member_data|pagination|comments|categories"}
     {if count =="1"}<ul id="clients-logos">{/if}
     <li class="{switch="clear||"}">
      {if "{exp:playa:total_parents field="client-name"}"}
      {exp:playa:parents channel="testimonial"}
      
       <a href="/clients/testimonial/{url_title}">_  _  {/exp:playa:parents}{client-logo}</a>
      {if:else}
      {client-logo}
      {/if}
     </li>
     {if count == total_results}</ul>{/if}
    {/exp:channel:entries}
  • #9 / Nov 29, 2011 4:59pm

    e-man

    1816 posts

    Looks good, was going to suggest that everything inside the {playa} loop references the other channel but you’d already found it. Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases