// get all pages that have at least 1 quote
$res = $pages->find("employee_quotes.count>0");
// add all quotes to an PageArray
$allquotes = new PageArray();
foreach($res as $r) $allquotes->add($r->employee_quotes);
// shuffle or whatever you please
$allquotes->shuffle();
// output all
foreach($allquotes as $q){
echo "<p>$q->employee_quote</p>";
}
Repeatable Fields
#161
Posted 25 May 2012 - 03:40 AM
@somartist | modules created | support me, flattr my work flattr.com
#162
Posted 25 May 2012 - 03:57 AM
This is what I've been looking for. Thanks you very much! *double like this* So in retrospect it was my way of thinking. I thought that with the $pages->find you can also find the fields. Now I see it doesn't make sense at all the way I was thinking. I dig deeper into PW with PageArray().
Thanks all for your thoughts!
#164
Posted 30 May 2012 - 09:52 AM
Tina // TinaciousDesign.com // @tinaciousdesign
#165
Posted 15 June 2012 - 12:58 PM
I have several pages with a repeater field and I want to display the fields, organized by page:
<h2>Page Title</h2>
<ul>
<li>repeatable field info</li>
<li>repeatable field info</li>
<li>repeatable field info</li>
<li>repeatable field info</li>
<li>repeatable field info</li>
</ul>
<h2>Page Title</h2>
<ul>
<li>repeatable field info</li>
<li>repeatable field info</li>
<li>repeatable field info</li>
<li>repeatable field info</li>
<li>repeatable field info</li>
</ul>
<h2>Page Title</h2>
<ul>
<li>repeatable field info</li>
<li>repeatable field info</li>
<li>repeatable field info</li>
<li>repeatable field info</li>
<li>repeatable field info</li>
</ul>
Like so. The array that Soma and diogo wrote seems like the ticket but does that just return the contents of the array as one big list or can it be organized by page? I have no idea how you'd do that.
#166
Posted 15 June 2012 - 01:27 PM
foreach( $pages->get("/someparent/")->children() as $pa ) {
// $pa is the page
echo "<h2>$pa->title</h2>";
echo "<ul>";
// cycle the repeater field as if they are pages (they are)
foreach( $pa->repeaterfield as $rp ) {
echo "<li>$rp->info</li>";
}
echo "</ul>";
}
@somartist | modules created | support me, flattr my work flattr.com
#167
Posted 15 June 2012 - 02:36 PM
I thought it must be easier than I was making it and that something was just a little off on what I was doing. I had pretty much what you have (you showed me a few ways to simplify things) but it wasn't working. With your example to go by as correct, I figured there was something else wrong so I looked at my selector and found my problem.
Now all I need to do is glue the hair I pulled out trying to get this, back on my head. Thanks again.
#168
Posted 15 June 2012 - 03:18 PM
Just for throwing in when using
<? foreach( $pages->get("/about/")->children() as $pa ) : ?>
<h2><?= $pa->title ?></h2>
<? if( count( $pa->teasers ) ): ?>
<ul>
<? foreach( $pa->teasers as $rp ) : ?>
<li><?= $rp->element_title ?></li>
<? endforeach ?>
</ul>
<? else: ?>
<p>No entries found</p>
<? endif ?>
<? endforeach ?>(short tags needs to be enabled on server, but only few hostings have it disabled. In near future it will always be enabled in php5.4)
@somartist | modules created | support me, flattr my work flattr.com
#171
Posted 05 July 2012 - 04:32 AM
Also: are you sure you really need repeater inside a repeater? Of course depends on your use case - it very well might be the best possible solution here.
#172
Posted 05 July 2012 - 04:52 AM
How does it fails? Does firebug or chrome console give you any error messages?
Also: are you sure you really need repeater inside a repeater? Of course depends on your use case - it very well might be the best possible solution here.
Processwire returns this on upload
{"error":false,"message":"Page not saved (no changes)"}
I could end with subpages with repeaters on each of them but page structure is more logical if there would be possibility to use nested repeaters on it
#173
Posted 05 July 2012 - 12:16 PM
Iam using in one project Repeatable Fields inside another Repeatable Fields. Everything works find except image uploads in inner Repeatable Field.
Unfortunately I don't think that file fields can be nested beyond one level of repeaters. There is some necessary security going on behind the scenes that limits the scope of how deep an ajax request can go, and I think that's what you are running into here. The truth is that you may actually be able to get it to work if it weren't using ajax uploads (like if you were using Safari, which doesn't support ajax uploads). But I think you may be better off avoiding nested repeaters if possible. Nested repeaters are a rather complex thing to develop around and may be difficult to maintain vs. a simpler solution that doesn't rely on nesting. Still, you've got me curious and I do plan on experimenting here and trying to duplicate the next time I'm working with repeaters, just to be certain I'm right about the reason it's not working. If there is an easy way around it, I'll find it. Nested repeaters do sound fun.
#174
Posted 11 July 2012 - 01:03 PM
It seems I found another bug with repeaters (unless it was already reported, though I didn't find about it in his thread)...
Here is what I did:
- I created one repeater field named "sliders" containing 3 fields title, body and images
- I added the field sliders to my home template
- I added 3 elements of type sliders on my homepage (which uses the home template), filling each with a title, a body and one image
- then I went back to the Fields manager and created a new repeater field named features by cloning the sliders field so features will have the same 3 fields title, body and images
(so far so good)
- went back to editing my homepage, and here the problem starts...
- first it already contained 3 elements of type features being a copy of my 3 previously created elements of type sliders (fine because I needed 3 elements anyway, "I'll just have to edit them" or so I thought)
- but then if I edit any field of, say, "Features #1" element, the change is also made to element "Sliders #1" !
- and I can't edit elements from sliders type anymore ! if I save a change in sliders, it is not applied; if I save a change in features, it is applied to features and sliders
Any idea ? Maybe I should not clone a repeater field ?
#175
Posted 11 July 2012 - 01:31 PM
#177
Posted 11 July 2012 - 01:56 PM
@Pete: He's talking about cloning fields rather than cloning pages. We did fix the issue with cloning pages that have repeaters. But cloning actual fields (Setup > Fields > some_repeater > Advanced > Copy/Clone) is a different thing.
Hope to find a way to make these cloneable. But since this is the first time it's come up, I don't think there's a lot of demand for cloning repeater fields. Unlike cloning pages with repeaters, which is probably a more common occurrence.
#178
Posted 11 July 2012 - 01:56 PM
I tried to delete all those repeaters and to recreate them; on my page I have a first repeater sliders and a second features which was created by cloning sliders. If I add a couple sliders items and save, the page will now have the same number of features items :'-(
EDIT: oh Ryan, you replied while I was typing this. That's fine, I will manually clone my repeater. Thanks
#179
Posted 11 July 2012 - 02:01 PM
#180
Posted 13 August 2012 - 05:10 PM
foreach($page->get("product") as $item) {
if (count ($item->product_shot) > 1) {
echo "<div class='productcontainer'><div class='prodpic'><a class='nowandthen'><img src='{$item->product_shot->url}' alt='{$item->product_shot->description}'>
<img src='{$item->product_shot->url}' alt='{$item->product_shot->description}'></a></div>\n<div class='prodtext'><h2>{$item->product_name}</h2>\n{$item->product_description}</div></div>";
} else {
echo "<div class='productcontainer'><div class='prodpic'><img src='{$item->product_shot->url}' alt='{$item->product_shot->description}'></div>
\n<div class='prodtext'><h2>{$item->product_name}</h2>\n{$item->product_description}</div></div>\n";
}
}
I get
<img src='/pw/site/assets/files/1010/' alt=''>in the markup while the name and description displays correctly.
I have almost the same set up in my own photography site for the galley where I have a name field and description associated with each image and it works (although I don't remember how I got it to work because it didn't at first either). is my selector wrong? "Product" is the repeater.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













