davenorton Posted March 25, 2018 Share Posted March 25, 2018 Hi All I'm new to process wire and haven't touched php in about 8 years, however, from the lack of questions on the subject, I'm assuming this is not a common issue and more than likely my own doing. I am using the default site template t get to know the product and have added a simple function to the _func.php code file. I am further, using the default pages: Now I have added the simple function: function getHomePageName() { $homepageName = ''; if($pages){ $homepage = $pages->get('/'); $homepageName = $homepage->name; } else $homepageName = 'Nothing found'; return $homepageName; } The $pages object always null and the code Any help in determining why the the $pages object is null would be appreciated Thanks Dave N Link to comment Share on other sites More sharing options...
Wanze Posted March 25, 2018 Share Posted March 25, 2018 Hi @davenorton Welcome to ProcessWire! It is a scope problem: The $pages variable is not known inside your function by PHP. Use the global wire() function to get any API variable. At the beginning of your function, write this: $pages = wire('pages'); And it should start to work. Cheers 2 Link to comment Share on other sites More sharing options...
adrian Posted March 26, 2018 Share Posted March 26, 2018 Or if you prefer you could turn on the functions API: https://processwire.com/blog/posts/processwire-3.0.39-core-updates/#new-functions-api and do this: $homepage = pages('/'); PS Welcome to the forums! 2 Link to comment Share on other sites More sharing options...
davenorton Posted March 26, 2018 Author Share Posted March 26, 2018 Thanks for the swift response guys, and the solutions. 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