Forum
How can I access the ALL the content within a repeater, to be displayed using a...
Is this possible?
Example: I have a template that my client can use to make a music album. It contains a repeater so they can build up the playlist of mp3's.
I then want to access the content generated with the repeater and display it using a seperate template elsewhere on the site.
so my home page uses this code:
<?php
perch_content_custom('albums', array(
'template' => 'album-grid.html',
'count' => 10,
'page' => '/members/download-area.php',
));
?>
to call this template:
<ul data-playlist="<perch:content id="atitle" type="text" urlify="true"/>" style="display:none">
<perch:repeater id="track-listing" scope-parent="true" >
<li>
<a class="fap-single-track" href="<perch:content id="sample-track" type="file" />" title="<perch:content id="parent.atitle" type="text" />" target="<perch:content id="mp3-dl" type="file" />" rel="<perch:content id="parent.image" type="image" width="65" height="65" crop="false" />"><perch:content id="parent.atitle" type="text" /></a>
</li>
</perch:repeater>
</ul>
to access the content within this template:
<perch:repeater id="track-listing" label="Album Tracks" scope-parent="true">
<tr>
<td>
<perch:content id="track-name" type="text" label="track name" order="1" />
</td>
<td>
<a class="fap-single-track btn btn-danger" href="<perch:content id="sample-track" type="file" label="preview MP3" />" title="<perch:content id="track-name" type="text" />" rel="<perch:content id="parent.image" type="image" width="65" height="65" crop="false" />">
<i class="fa fa-play"></i>
</a>
</td>
<td>
<a href="<perch:content id="mp3-dl" type="file" label="MP3 Track" help="upload MP3 track as zip" order="3" />" class="btn btn-success" role="button">
<i class="fa fa-download"></i>
</a>
</td>
<td>
<a href="<perch:content id="wav-dl" type="file" label="WAV Track" help="upload WAV track as zip" order="4" />" class="btn btn-success" role="button">
<i class="fa fa-download"></i>
</a>
</td>
</tr>
</perch:repeater>
<perch:content id="slug" for="atitle" type="slug" suppress="true" />
The above code are only fragments of the templates, content from outside of the repates also needs to be resued, but that I understand how to achieve that.
I need a solution that will display the every repeated piece of content, not just the first (I do realise the code in the first template is incorrect - but it's the only way I have found to get perch to at least find the first instance and display only the content tags I have selected.
I hope that makes some sense... thanks
I'm not clear what you're asking. Are those supposed to be the same repeater? They have different IDs.
Sorry Drew - I was editing the post and my laptop battery died. Yes the repeaters actually have the same ID.
I'm finding it hard to explain it clearly.
I want to reuse the content generated within a repeater - using another template, on another page of the site.
Ok, that's very straightforward to do. How is it failing?
Using the first template example as it is, it only display's the first track.
I'm not getting how I call the content I want from the second example, but have Perch display every repeated instance.
The repeater seems to only contain
parent.
IDs - is that right?Basically your repeater has no content.
I have updated the code to the my latest attempt.
Referring to my second template example (which is the master template): The parent.id's are calling things like the album cover artwork and album title, which are used elsewhere in the template. The mark-up within the repeater needs to reuse that content as thumbnails, meta data etc
There are other id's within the repeater, such as "mp3-dl" that are unique to the repeater.
So it's a mixture of content both in and out of scope.
I would like to get the template in the first example to display every instance of "mp3-dl".
You're right in saying that the first example has not content - as it cannot be edited in perch as it is. The content is meant to be pulled in from the master template - but I am only getting 1 instance...
That's what the code you now have should be doing.
What HTML result do you get?
Yes - I understand that, but I need help on how to mark it up so it repeats the <li>...</li> as many times as necessary.
Maybe I need a different approach - In the first code example: Can I access the content from the repeater (in the second example) without using a repeater tag?
the first example generates this (as expected):
But I am using the repeater several times to generate content in perch - what about the other instances?
But I am still unclear on how to access the content within a repeater from another template.
If the user generates 10 items, can that content be reused in a separate template?
Or can that only be done using perch_content_custom and not with template tags?
A repeater will display all the items unless you take action to limit it.
How many items are in your repeater?
What about referencing a repeater from another template? how is that achieved? Does the new template need it's own repeater region (as I have attempted) or is there another way?
I'm using perch_content_custom to call the content from the 'albums' region, but my template 'album-grid' need to pull the info from the repeater region in the original template being used for 'albums'.
Average 10-12 items in a repeater...
Using a repeater in another template is no different from other fields - just copy the
<perch:repeater>
tags to the new template, then useperch_content_custom()
to redisplay that region with the new template.okay thanks, that pretty much sums up what I have done - but I can't work out why it only displays 1 of the repeater items, not all of them...
Can you reduce it to a simple test case?