Manol Posted October 13, 2015 Posted October 13, 2015 Hi guys. Is there a way to get fields included within a FieldsetOpen? I would like to render in the frontend in several columns FieldsetOpen labels and the fields within it. Thank you.
diogo Posted October 13, 2015 Posted October 13, 2015 Fieldsets were not designed for that purpose, so it's a bit harder than you may think. Have a look at the solution here https://processwire.com/talk/topic/10226-getting-fields-in-a-fieldset/
Manol Posted October 14, 2015 Author Posted October 14, 2015 Finally I got it. Here is the code and a couple of self explanatory images to show what you have and what you get. protected function getFieldsets( $pageID ){ $pagina = wire('pages')->get($pageID); $campos = array(); $array = array(); $temp = null; foreach($pagina->fields as $field) { if($field->type->name == "FieldtypeFieldsetOpen") { $temp = $field->name; } elseif($field->type->name == "FieldtypeFieldsetClose") { $campos = array(); $temp = null; } else { if($temp!=null){ array_push($campos, $field->name); $array[$temp]= $campos; } } } return json_encode($array); } 1
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