jeremie Posted November 2, 2020 Share Posted November 2, 2020 (edited) Hi, sorry for the very nubby question but i can't understand why <?php echo $page->categories; ?> renders me 1041 instead of the name of the categorie I define categories being the name of the field I define thanks for your help Edited November 2, 2020 by jeremie Link to comment Share on other sites More sharing options...
OLSA Posted November 2, 2020 Share Posted November 2, 2020 Hi, that is ok. because ProcessWire by default in that case return Page ID (response from __toString() method inside Page class). And, as example to get page "title" append field name: echo $page->category->title; If it is array of pages you can iterate: foreach($page->categories as $category){ echo $category->title; } There are also many other options inside PW api, and as example, to get single Page item inside Pages you can get it by index: // get first category title $n = 0; echo $page->categories->eq($n)->title; More about Page or Pages. Regards. 1 Link to comment Share on other sites More sharing options...
jeremie Posted November 2, 2020 Author Share Posted November 2, 2020 Thank you very much for your answer. strangely echo $page->category->title; doesn't seem to work but the last example works perfectly Link to comment Share on other sites More sharing options...
elabx Posted November 2, 2020 Share Posted November 2, 2020 19 minutes ago, jeremie said: Thank you very much for your answer. strangely echo $page->category->title; doesn't seem to work but the last example works perfectly That would seem to be because your "categories" field is a Page field configured for multiple pages? If that is the case, it's normal that the "categories" property wouldn't have at title property itself, because it outputs as PageArray. Link to comment Share on other sites More sharing options...
jeremie Posted November 2, 2020 Author Share Posted November 2, 2020 thank you elabx this was the problem ? 1 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