SETUP:
Fields I have (uses:Page), (instances:Page) and (categories:Page). Please see the attached file.
[ uses ] Selection of fields to render. See the attached file # 2
[ instances ] "Default" data for pages. See the attached file # 2
[ categories ] A bunch of items
CODE:
Renders the selected field from [ uses ] to the template. It's a simple way of not hard-coding the fields in your page. NOTE: Pagefields() is a function inside /site/templates/home.php
ISSUE:
I do not know how to exclude the parent's field ($fo->title) from field ($page->instances) (Categories). Which is foreach($page->{strtolower($p->title)} as $fo){} thus returning $fielddata. I want to get only the titles from ($fo->categories) and not the (Categories) title. I hope I am making sence. See the attached file # 3.
Field (uses)
Example: I select a field called (categories) from [ uses ] it outputs the title "2D". For this to work the current page or template has to have that field from [uses] or it will not work. See the attached file # 2
<?php
function Pagefields(Page $page, Pages $pages, Fields $fields){
$fielddata = array();
foreach($page->uses as $p){
var_dump($p->title); // OUTPUTS. instances, categories
foreach($page->{strtolower($p->title)} as $fo){
$fieldr = strtolower($fo->title);
var_dump($fo->title); // OUTPUTS. Categories, 2D
$fielddata[] = $fo; // Returns the title (Categories) which I don't want. I do need to return the titles inside Categories with a field called (categories).
if($page->get($fieldr)!=NULL){
foreach($fo->{$fieldr} as $f1){
$fielddata[] = $f1;
var_dump($f1->title); // OUTPUTS. Blender (software), CSS 3, HTML 5, Design, Development, 2D, 3D, Vehicle Design. See the attached file # 3
}
}#endof: if($page->get($fieldr)!=NULL){}
}
} #endof: foreach($page->uses as $p){}
return (object) $fielddata;
}
foreach(Pagefields($page, $pages, $fields) as $p){
var_dump($p->title);
}
HARD-CODED VERSION: This is the other way of doing my code above. I do not want to hard-code the field names in my home.php file
I have debug set to TRUE and I get the following error.
<?php
foreach($page->instances as $p){
foreach($p->categories as $cat){
var_dump($cat->title); // OUTPUTS. Blender (software), CSS 3, HTML 5, Design, Development, 2D, 3D, Vehicle Design. See the attached file # 3
}
}
## Warning: Invalid argument supplied for foreach() in line 2 foreach($p->categories as $cat){}













