I have a channel for “Periods of Time”(child) and a channel for “Artifacts”(parent). In the Artifacts publish forms I have a relationship field for the user to select which “Period of Time” the article belongs in.
In my template I’m displaying the “Periods of Time” using a channel entries tag. Within those entries, I have a “parents” tag to display the Artifacts that have been related to it. This is working great.
Within this parents relationship loop, I need to display the other Artifacts that have been related to the “Period Of Time” entry. Can’t wrap my head around how i would pull that. I was going to setup another relationship field in the “Artifacts” channel to select other Artifacts from the same Period, but thinking that might be redundant. While I’m in a parents relationship loop, can I pull the Artifacts again? maybe siblings tag? my end of day friday brain isn’t working for this, any help would be appreciated.
{exp:channel:entries channel="periods" disable="categories|member_data|category_fields|pagination" sort="asc" dynamic="no"}
{title}
{parents field="artifact_period"}
{parents:title}
<!--this might seem weird, but here I need to display the other Artifacts that have been related to the "Period of Time" -->
{/parents}
{/exp:channel:entries}
I have a “parents” tag to display the Artifacts that have been related to it.
I need to display the other Artifacts that have been related to the “Period Of Time” entry
Aren’t you already doing that with your parents tag? If not, can you describe what the “other Artifacts” are and how they are related to the period
entry being displayed?
Derek, thanks for replying, it is confusing, hopefully I can explain what I’m doing…
I’m listing Periods using the channel entry tags, within each of those periods I’m listing the Artifacts related to each Period. When a user clicks an Artifact, it opens a popup that has content about that Artifact. It also will list the other 2 Artifacts within that period so a user can jump right to those popups from within the popup they are viewing. This all might make a little more sense if I told you this isn’t really a website, it’s an interactive multi-user touch-screen display. So a user will scroll through each period and view the Artifacts and they can touch on a Artifact to launch the popup. While viewing the content within that popup another user can keep scrolling so we wanted a way for the first user to view the other Artifacts within the Period they were in, so the other Artifacts within that period will be listed in the popup. Tapping on an Artifact in that list will launch that artifact’s popup.
So basically we are loading the parent’s list again within the parent’s list I think. Maybe an embed will be required here?
Ah, gotcha, also very cool!
To give you specific implementation advice, I’d need to see your full templates to see how you’re handling the popups, etc. If you’re making a new HTTP request to display the popup, I’d provide one solution. If you’re loading all of the artifact content into the DOM at once, there’d be another. I don’t think an embed is necessary either way. You’re either listing parents, or siblings, and both have corresponding relationship tags. Make sense?
Derek, I just got done getting this to work with an embed, but would love to hear if you have a cleaner idea. The modal code is generated within the same html document so it isn’t an external call. I’ll paste my current template code and embed code that appears to be working with my initial testing. if there is a way to eliminate the embed that would be great, but for this project, any slowdown the embed might create, won’t really matter as the whole “page” will be loaded already for the touchscreen.
{exp:channel:entries channel="periods" disable="categories|member_data|category_fields|pagination" sort="asc" dynamic="no"}
<!--===========================-->
<!-- PERIOD -->
<!--===========================-->
<section id="period-{period_year}" class="period" data-period-color="{period_color}">
<!-- TITLE CARD -->
<!--===========================-->
<a href="#" class="show-modal period-title-card">{title}</a>
<!-- ARTIFACTS -->
<!--===========================-->
{parents field="artifact_period"}
<a href="#" class="show-modal artifact artifact-{parents:artifact_size} artifact-{parents:artifact_v_alignment} artifact-{parents:artifact_h_alignment}">_ <span class="artifact-title">{parents:title}</span>_ {parents:artifact_main_image}{img:url}{/parents:artifact_main_image}_ </a>
<!--===========================-->
<!-- ARTIFACT MODAL -->
<!--===========================-->
<section id="period-{parents:artifact_year}-artifact-{parents:count}" class="modal modal-hidden modal-{period_color}" data-name="{title}">
<div class="modal-articles">
<a href="#%22class=%22modal-article" title="Period" class="modal-article">_ <div class="object-list-img-wrap" url('/images/uploads/Narmer_Palette_pubdom.png');"> _ </div> _ <h1>{parents:title}</h1> _ </a>
{/if}
{/parents}
{/exp:channel:entries}
</article>
Something in my code, the embed tag I think, within the code block is making the forum throw some errors and cut off my template post :/ So here are some screenshots…
[Template Code](https://www.dropbox.com/s/ucb864c9cr6of4t/Screen Shot 2017-08-07 at 10.37.57 AM.png?dl=0) [Embed Code](https://www.dropbox.com/s/dhcolq7bjdzu6c8/Screen Shot 2017-08-07 at 10.38.11 AM.png?dl=0)
Thanks! Looks like your embed is recreating the channel entries tag and the parents relationship, so I think your embed is redundant. You should be able to to just place this template code where you currently have your embed tag:
{if parents:artifact_year != parents:count}
<a href="#" class="object-list-item close-modal show-modal">_ <div class="object-list-img-wrap" url('/images/uploads/Narmer_Palette_pubdom.png');"> _ </div> _ <h1>{parents:title}</h1> _ </a>
{/if}
Update: ok I see the issue you were having with the code samples. Security filter is probably ratcheted up a little high. Here is a gist of the code
Note: conditional variables should not be braced
Derek, I appreciate the help. The parents:artifact_year and parents:count variable don’t have any relation, so I’m not sure why you are comparing them in the conditional. I’m basically looping through and displaying the Artifacts using the relationship parents tags, then within those entries, running through the same loop again to display them within each Artifact. Not sure how to do that without an embed.
Ok now I think I gotcha - you want the variables of all of the other parents available to you while displaying the details of a given parent. So what you are looking for is the siblings tag. You should be able to use that within your parents tag without any embeds.
Re: the conditional, I probably had a cut and paste error when translating embed:current_artifact_count
and embed:current_artifact_year
to in-context variables, sorry!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.