bbb Posted September 12, 2017 Share Posted September 12, 2017 $footer_items = $pages->get("/")->nav_footer; foreach($footer_items as $footer_item){ echo "<li><a class='menu-item' href='$footer_item->url'>$footer_item->title</a></li> "; } I have this code in my footer which is an included php file. On my homepage template I have a page field with multiple pages selected which I use to create a row of links. This works on every single page/template except on the homepage itself where I get a Warning: Invalid argument supplied for foreach(). I've also tried using $footer_items = $page->nav_footer; That also gives me an error. What am I missing? Link to comment Share on other sites More sharing options...
kongondo Posted September 12, 2017 Share Posted September 12, 2017 Works fine here. What does debug and/or Tracy tell you is the value of $footer_items when viewing the home page? Maybe there's some template level restriction? Link to comment Share on other sites More sharing options...
bbb Posted September 12, 2017 Author Share Posted September 12, 2017 8 minutes ago, kongondo said: Works fine here. What does debug and/or Tracy tell you is the value of $footer_items when viewing the home page? Maybe there's some template level restriction? NULL Link to comment Share on other sites More sharing options...
bbb Posted September 12, 2017 Author Share Posted September 12, 2017 Tried renaming the field. Tried creating a whole new field. Link to comment Share on other sites More sharing options...
abdus Posted September 12, 2017 Share Posted September 12, 2017 Some debugging ideas: // check which fields are added to the page dump($page->fields->explode('name')); dump($pages(1)->fields->explode('name')); // get the first page reference field of the page $pageFieldName = $page->fields->findOne('type=FieldtypePage')->name; dump($page->$pageFieldName); Link to comment Share on other sites More sharing options...
kongondo Posted September 12, 2017 Share Posted September 12, 2017 1 hour ago, Barry said: NULL Strange one. I am wondering if some code is overriding $page when viewing the home page. Do other fields on 'Home' work fine? Link to comment Share on other sites More sharing options...
bbb Posted September 12, 2017 Author Share Posted September 12, 2017 48 minutes ago, kongondo said: Strange one. I am wondering if some code is overriding $page when viewing the home page. Do other fields on 'Home' work fine? I've tested this and $page->name and title and url all work fine. My homepage template doesn't have any other custom fields besides the already mentioned footer_nav Link to comment Share on other sites More sharing options...
kongondo Posted September 12, 2017 Share Posted September 12, 2017 Only thing left to look at is your relevant template files code, the code in the include file as well as the settings of your page field (just in case). Any restrictions on who can view home page? Link to comment Share on other sites More sharing options...
bbb Posted September 12, 2017 Author Share Posted September 12, 2017 embarrassed to admit that after some thorough digging, I found if($page->template = 'pageGeo'){ instead of with == which was messing up everything. 2 Link to comment Share on other sites More sharing options...
adrian Posted September 12, 2017 Share Posted September 12, 2017 6 minutes ago, Barry said: embarrassed to admit that after some thorough digging, I found if($page->template = 'pageGeo'){ instead of with == which was messing up everything. You're in good company - we've all done that one 1 Link to comment Share on other sites More sharing options...
kongondo Posted September 12, 2017 Share Posted September 12, 2017 8 minutes ago, Barry said: if($page->template = 'pageGeo') One trick is to do this instead... if('pageGeo' == $page->template) If you mistyped that as: if('pageGeo' = $page->template)// syntax error // OR even if(1 = $page->id)// syntax error PHP will throw a Parse Error: syntax error, unexpected '=' , immediately alerting you of your mistake . 4 Link to comment Share on other sites More sharing options...
szabesz Posted September 13, 2017 Share Posted September 13, 2017 8 hours ago, kongondo said: If you mistyped that as: if('pageGeo' = $page->template)// syntax error // OR even if(1 = $page->id)// syntax error I have never thought of it but it is so obvious. We are simply trained to do it the other way round. Anyway, my NetBeans marks such an issue on the fly which is hard to miss, and that is why I do not make this mistake these days, otherwise... 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