Harmster Posted September 16, 2012 Share Posted September 16, 2012 Hey, I am quite new to Processwire and to this forum ,as you can see. Although I am really starting to become a fan of processwire. But the amount of topics on the forums is somewhat limited. Doesn't matter but I can't really find the answer to my question. I do want to retrieve all the fields (type's and values) from a page, and display them. I do got this: <?php $u = new nubUsers(); if($u->is_manager()){ $id = $input->get('id'); $p = new NubPages(); $r = $p->edit_page($id); $f = $fields->find("page=$r->id");//get all the fields ?> <h1>Edit page <?php echo $r->title; ?></h1> <?php }else{ throw new Wire404Exception; } ?> With edit_page would be: public function edit_page($id){ $p = wire('pages')->get("id=$id"); return $p; } How could I get this done? Sorry if this is already answered, explained somewhere else or anything like that, but if so i couldn't really find it :\ Kind regards, Harmster. 1 Link to comment Share on other sites More sharing options...
ryan Posted September 17, 2012 Share Posted September 17, 2012 I'm not sure I understand the example. What is NubUsers and NubPages? Also something like $fields->find("page=$r->id"); is completely unfamiliar to me. It seems like there are some parts ProcessWire and some parts something else? I do want to retrieve all the fields (type's and values) from a page, and display them. Here's a simple example that does exactly that: foreach($page->fields as $field) { echo "<p>"; echo "Field: {$field->name}<br />"; echo "Type: {$field->type}<br />"; echo "Value: " . $page->get($field->name); echo "</p>"; } 5 Link to comment Share on other sites More sharing options...
Harmster Posted September 17, 2012 Author Share Posted September 17, 2012 I'm not sure I understand the example. What is NubUsers and NubPages? Also something like $fields->find("page=$r->id"); is completely unfamiliar to me. It seems like there are some parts ProcessWire and some parts something else? Here's a simple example that does exactly that: foreach($page->fields as $field) { echo "<p>"; echo "Field: {$field->name}<br />"; echo "Type: {$field->type}<br />"; echo "Value: " . $page->get($field->name); echo "</p>"; } Thank you for your quick reply! yeah, i kind of made my own classes to get a bunch of repatative stuff done. I feel stupid that it is that simple... Ty Ryan! Link to comment Share on other sites More sharing options...
SiNNuT Posted September 17, 2012 Share Posted September 17, 2012 Harmster, have you already seen the cheatsheet? It's really helpful for figuring out stuff like this. For example $page->fields is in there. Clicking on the items give a small description of what it is. Also, if your doing some 'custom' user stuff it might be worth noting that you can edit the user template just like other templates. You can add your own fields. A user is a page object, see Admin->Access->Users. 1 Link to comment Share on other sites More sharing options...
Harmster Posted September 17, 2012 Author Share Posted September 17, 2012 Harmster, have you already seen the cheatsheet? It's really helpful for figuring out stuff like this. For example $page->fields is in there. Clicking on the items give a small description of what it is. Also, if your doing some 'custom' user stuff it might be worth noting that you can edit the user template just like other templates. You can add your own fields. A user is a page object, see Admin->Access->Users. Thank you for your response, I forgot about the cheatsheet i guess... still new to all this... Although I did edit the template and I did make some custom classes to do some repetative actions on that template etc. Link to comment Share on other sites More sharing options...
gfdesign Posted June 11, 2013 Share Posted June 11, 2013 Sorry. And In case I need to get just one field from a specific page?I'd want to get the value of the field "enlace" (where I keep an URL value) in the page "store" to use in the main menu in all the pages. How would you do it? Do I need to do a foreach anyway? Link to comment Share on other sites More sharing options...
kongondo Posted June 11, 2013 Share Posted June 11, 2013 (edited) Sorry. And In case I need to get just one field from a specific page? I'd want to get the value of the field "enlace" (where I keep the an URL value) in the page "store" to use in the main menu in all the pages. How would you do it? Do I need to do a foreach anyway? Rule of thumb: many things -> foreach one thing -> grab and echo directly In your case, if what you want is on another page echo $pages->get(123)->enlace; //123 is ID of that page You can also use path to that page instead of ID. Please have a look at the API documentation. Everything to get your started is explained there http://processwire.com/api/. Look at variables and selectors in the first instance. Edit: Quick addition for newbies - what Harmster wanted in the first post were the names and the values of Fields which is different from what gfdesign needs Edited June 11, 2013 by kongondo 2 Link to comment Share on other sites More sharing options...
gfdesign Posted June 11, 2013 Share Posted June 11, 2013 Perfect. I knew it was very simple BTW, How do you know what's the ID of any page besides when you're over 'edit' link in the Admin Panel?I mean, can you see the ID in some place of Admin area? Link to comment Share on other sites More sharing options...
kongondo Posted June 11, 2013 Share Posted June 11, 2013 You can also see it in the URL when editing the page . Or echo echo $page->id; in your template file when developing . Of course, delete code when done 1 Link to comment Share on other sites More sharing options...
diogo Posted June 11, 2013 Share Posted June 11, 2013 You can also add the ID to the "list of fields to display in the admin page list" field on the advanced tab on each template. To do it quickly for all templates, put this code on any page and load it: // get all templates foreach ($templates as $t) { // if fields are the default (empty shows only the title) if ($t->pageLabelField == "") { // make new string with title and id $t->pageLabelField = "title id"; } else { // if not, add " id" to the existing string $t->pageLabelField .= " id"; } // save the template $t->save(); } 1 Link to comment Share on other sites More sharing options...
kongondo Posted June 11, 2013 Share Posted June 11, 2013 You can also add the ID to the "list of fields to display in the admin page list" field on the advanced tab on each template. Aah...thought about this but PW only suggested other fields as available to add. Link to comment Share on other sites More sharing options...
diogo Posted June 11, 2013 Share Posted June 11, 2013 And to revert (removes the id from the end of the string): foreach ($templates as $t) { $t->pageLabelField = preg_replace('/ id$/', '', $t->pageLabelField); $t->save(); } Link to comment Share on other sites More sharing options...
hsanabria Posted June 16, 2015 Share Posted June 16, 2015 I am creating a custom search routine and this code has been very useful to encompass all fields of the site pages. foreach($page->fields as $field) { echo "<p>"; echo "Field: {$field->name}<br />"; echo "Type: {$field->type}<br />"; echo "Value: " . $page->get($field->name); echo "</p>"; } But I failed to get the subfields of repeater's field type Any suggestions? Link to comment Share on other sites More sharing options...
tekno Posted August 11, 2015 Share Posted August 11, 2015 hi i tried this but i cant success. there is a template as products.php and a field as product_type i want to list all product_type values for search form. how can i print this uniq values? Link to comment Share on other sites More sharing options...
Macrura Posted August 11, 2015 Share Posted August 11, 2015 @tekno, can you explain more about what you want to do? there are several ways to get a list of unique values, but depends on how the fields are setup and how your search form needs to reference them. 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