Jump to content

Creating new FieldsArray or filtering $page->fields


Robin S
 Share

Recommended Posts

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

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"));
  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...