Ksenia Posted November 25, 2021 Share Posted November 25, 2021 Hello! I am still exploring how PW works and I am facing this issue: I want to create a selector for a field that is PageReference type (AsmSelect) inside the repeater field. It goes like this: Relation to Document: Select: (you pick Document/Documents) Type: (you pick type/types of relation which are also pages) This is how I find the pages that have current page in the Repeater field, it works: $selector_doc = "template=Document, relation_document_document.relation_document_document_select=$page->name"; But the problem is with how to filter based on repeater entry, meaning if there are multiple entries (its a different repeater, but identical): How do I say "if SELECT == '$page->name', then print it "select and type"? Because now it just loops through all of the Relation entries, but I want it to show me only the one that has current page in Select: My code: $techniques = new PageArray(); $selector_tech = "template=Technique, relation_technique_substance.relation_technique_substance_select=$page->name"; $techniques->add($pages->find($selector_tech)); if (sizeof($techniques) > 0) { echo "<div class='field-cont'>"; echo "<div class='field-name'>Linked techniques:</div>"; echo "<div class='trick'>"; echo "<div class='field-lists tech'>"; foreach ($techniques as $tech) { foreach ($tech->relation_technique_substance as $relation_technique_substance) { $arraySelect_trick = $relation_technique_substance->relation_technique_substance_select; $arrayType_trick = $relation_technique_substance->relation_technique_substance_type; echo "<div class='field-relation'>"; ////here needs to be If()/// echo "<div class='select'>"; echo "<li><a href='$tech->url'>$tech->title</a>"; echo "</div>"; echo "<div class='type'>"; foreach ($arrayType_trick as $item) { echo "<span>$item->title</span></li> "; } echo "</div>"; /// end if echo "</div>"; } } echo "</div></div></div>"; } Best, Ksenia Link to comment Share on other sites More sharing options...
Robin S Posted November 26, 2021 Share Posted November 26, 2021 A few suggestions: 1. It's best to match using a page's ID rather than its name, because the ID is globally unique but the name is not. So instead of... $pages->find("template=Technique, relation_technique_substance.relation_technique_substance_select=$page->name") ...you can do... $pages->find("template=Technique, relation_technique_substance.relation_technique_substance_select=$page->id") ...and because the string value of a Page object is its ID it's typical to do... $pages->find("template=Technique, relation_technique_substance.relation_technique_substance_select=$page") 2. You don't need to create a PageArray and add pages to it because $pages->find() already returns a PageArray. So this... $techniques = new PageArray(); $selector_tech = "template=Technique, relation_technique_substance.relation_technique_substance_select=$page->name"; $techniques->add($pages->find($selector_tech)); ...can be simplified to... $techniques = $pages->find("template=Technique, relation_technique_substance.relation_technique_substance_select=$page"); 3. PageArrays have a count() method/property, so rather than... if (sizeof($techniques) > 0) { ...try... if ($techniques->count) { 4. To answer your main question, the value of a Repeater field is a (Repeater)PageArray so you can use ->find($selector) to search within it. foreach ($tech->relation_technique_substance->find("relation_technique_substance_select=$page") as $relation_technique_substance) { Now any Repeater items where relation_technique_substance_select does not include $page will be excluded. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now