Robin S Posted November 24, 2015 Share Posted November 24, 2015 Using $page->fields makes it easy to output field labels and values for a page in a foreach loop, which is great when you have fields that you want to output with the same markup structure. But what if I don't want all the fields in the page, but just some of the fields, so I can use two or three different foreach loops for different markup needs. The docs say that $page->fields returns a "FieldsArray". How can I create my own FieldsArray, selecting fields by name? Or maybe filter $page->fields by field name? Link to comment Share on other sites More sharing options...
adrian Posted November 24, 2015 Share Posted November 24, 2015 You can filter like this: foreach($page->fields->find("type=FieldtypeImage") as $f){ or you can create a new field array with: $myFields = new FieldsArray(); foreach(xxxx as $f){ $myFields->add($f); } 1 Link to comment Share on other sites More sharing options...
Robin S Posted November 24, 2015 Author Share Posted November 24, 2015 Thanks! I was hoping there was some sort of find method for page fields, and of the two options I'll probably use this. But for $myFields->add($f); ...if I know the name of the field I want to add to the FieldsArray, how do I get the item into the right type for adding to a FieldsArray? Edit: worked it out now... $myFields = new FieldsArray(); $myFields->add($page->fields->get("fieldname")); 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