justnew77 Posted December 9, 2013 Share Posted December 9, 2013 Hi, my site have a page that I use as an container. Name CONTAINER. CONATINER has children. Each of them has fields in it. What I want ist this: On an other page I want to list all the content of the fields from CONTAINER children. How can I do that? In MODx there was a plungin called getResources to do that. How it is here? Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 9, 2013 Share Posted December 9, 2013 (edited) MODX with getResource is slow & inflexible compared to ProcessWire, take a look at this traversing heaven. Something like this might work: foreach($pages->get('/CONTAINER/')->children as $p) { foreach($p->fields as $f) { echo $p->$f . "<br>"; } } Edited December 9, 2013 by Martijn Geerts 2 Link to comment Share on other sites More sharing options...
justnew77 Posted December 9, 2013 Author Share Posted December 9, 2013 Hm...that seems not to work?! Nothing happend! Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 9, 2013 Share Posted December 9, 2013 There was a bug in the code sorry. Maybe it's better to explain what i've done. // get the parent // the children of the page under www.your-domain.com/container/ $pages->get('/CONTAINER/')->children <-- this is a page array // now you can foreach this, because it is an array. $children = $pages->get('/CONTAINER/')->children; foreach($children as $p) { $all_fields = $p->fields; // fields are all the fields in the template from this page. (array) foreach($all_fields as $f) { // every field $f echo $p->$f . "<br>"; // $p, the page in the `outerloop`, $f all fields in $p } } Link to comment Share on other sites More sharing options...
justnew77 Posted December 9, 2013 Author Share Posted December 9, 2013 Sorry but i stuck a litte bit with that. Can you please write the complete code to retrieve the data? 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 9, 2013 Share Posted December 9, 2013 Where is /CONTAINER/ located ? And what are the names of your fields ? (ps, it's a good practice to lowercase all page names ) Link to comment Share on other sites More sharing options...
justnew77 Posted December 9, 2013 Author Share Posted December 9, 2013 Hm, sorry it retrieves nothing. Nothing appears! Link to comment Share on other sites More sharing options...
diogo Posted December 9, 2013 Share Posted December 9, 2013 To get content from a field of one children page that you know the name, do this; echo $page->get("parent=$page, name=name-of-page")->field; To get more fields do this: $myPage = $page->get("parent=$page, name=name-of-page")->field; echo $myPage->field1; echo $myPage->field2; To get the fields from all children do as Martijn pointed out. Basicly, you will be looping through all the children, and extract the fields from each one of them. An important thing to know is that get() get's one page and you can immediately retrieve the fields, while find() gets a group of pages and you only have access to their properties when you iterate them (with foreach() for instance.) 1 Link to comment Share on other sites More sharing options...
justnew77 Posted December 9, 2013 Author Share Posted December 9, 2013 Fieldname 1 is "folgeTitel", Fieldname 2 is "folgeYT" The pagename is "video-container" (i adapted it in the code trys)It is located in: Home |_Site 1 |_Site 2|_video-container The "data-pages" are childs from video-container Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 9, 2013 Share Posted December 9, 2013 $items = $pages->find('parent=/video-container/'); // find retrieves an Pagearray while get gets 1 page object. foreach($items as $item) { echo $item->folgeTitel . '<br>'; echo $item->folgeYT . '<br>'; } 2 Link to comment Share on other sites More sharing options...
diogo Posted December 9, 2013 Share Posted December 9, 2013 foreach($pages->get("/video-container/")->children as $p) { echo $p->folgeTitel . "<br>"; echo $p->folgeYT . "<br>"; } edit: Well, now you have two answers... find the differences 3 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 9, 2013 Share Posted December 9, 2013 Lol Link to comment Share on other sites More sharing options...
justnew77 Posted December 9, 2013 Author Share Posted December 9, 2013 Yes, Martijn, that works. Thank you for your great support. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 9, 2013 Share Posted December 9, 2013 And diogo ? Link to comment Share on other sites More sharing options...
diogo Posted December 9, 2013 Share Posted December 9, 2013 I got a like already Link to comment Share on other sites More sharing options...
justnew77 Posted December 10, 2013 Author Share Posted December 10, 2013 Hi there, I got a new field (an image field, only 1 images allowed) The problem now is that the images can not display becauese the field contains only the filename and NOT the path. echo "<img src='{$item->folgePic}'>"; What can I do to recieve the full path and name? Link to comment Share on other sites More sharing options...
diogo Posted December 10, 2013 Share Posted December 10, 2013 You should definitely read the docs... $item->FolgePic->url 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