Jump to content

fields render


jeremie
 Share

Recommended Posts

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 by jeremie
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...