0

I have a "Job Openings" channel with a relationship field. The field relates to the "Facility" channel. So when a user creates a new job opening entry, they relate the opening to the facility. Now in my template I want to display a list of facilities ONLY IF THEY HAVE JOB OPENINGS, then below the name of the facility, display all job openings.

I started with a channel entries tag for the facilities. How do I setup the conditional so it detects if there is a parent(job opening), display the facility title, then display all job openings for that facility? I only want the facility name to appear once, with all job openings for that facility below it.

The code I have below is not correct and displays the facility title for every job opening. I'm not sure how to setup the conditional correctly. Any ideas? Thanks for any help!

            {exp:channel:entries channel="facilities" disable="categories|member_data|category_fields" sort="asc" dynamic="no"}

            {parents field="job_facility"}
               {if parents:count >= "1"}
               <article class="job_summary">
                   <h1>{title}</h1>
                       <h2>Job Opening</h2>
                       <a href=""><h3>{parents:title}</h3></a>
               </article>
               {/if}
            {/parents}

            {/exp:channel:entries}

This is what I want...

  • Facility 1
    • job opening
  • Facility 2
    • job opening
    • job opening
  • Facility 8
    • job opening

And this is what I'm getting...

  • Facility 1
    • job opening
  • Facility 2
    • job opening
  • Facility 2
    • job opening
  • Facility 8
    • job opening
2
  • Try this: Around your h1 tags add {if parents:count =="1"}<h1>{title}</h1>{/if} – CreateSean Mar 19 '15 at 19:21
  • Sean, thanks for taking a look, Unfortunately that didn't make any difference. – Mike Lohrman Mar 19 '15 at 19:30
2

Expanding a bit on @CreateSean's comment to your question, you can use the parents:count and parents:total_results variables much like you'd use them in the Channel entries tag to generate "wrapper" markup.

{exp:channel:entries channel="facilities" disable="categories|member_data|category_fields" sort="asc" dynamic="no"}

  {parents}
      {if parents:count == "1"}
        <article class="job_summary">
          <h1>{title}</h1>
          <h2>Job Opening</h2>
      {/if}

             <a href=""><h3>{parents:title}</h3></a>

      {if parents:count == parents:total_results}
        </article>
      {/if}
  {/parents}

{/exp:channel:entries}
3
  • So simple, embarrassed my thought process didn't go there. Thanks Derek! – Mike Lohrman Mar 19 '15 at 19:34
  • one more quick question, is it possible to pull grid column data? For example, in the parent entry I have a Grid field called "facility_contact_info" with a field name called "joblink". Can the contents of "joblink" be pulled in as well? – Mike Lohrman Mar 19 '15 at 19:46
  • nevermind, I figured it out. – Mike Lohrman Mar 19 '15 at 19:51

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.