Jump to content

Can't echo page title


Jonathan
 Share

Recommended Posts

Hi PW community,

Here's my code: 

$films = $pages->find("template=film");
foreach($films as $film){
$poster = $film->poster->size(200, 280);
$g = $film->genre;
echo "..."

If I echo $g, I get the page id of each array item (eg. 1159|1245|1291 etc), but if I echo $g->title I get nothing.

I'm quite confused as if I echo $poster->url or path or name, that echoes out just fine.

Thanks in advance!

Link to comment
Share on other sites

Thanks Adrian, I knew it was a simple fix and had been trying to get implode working but found PHPs manual a bit confusing. Ryan's examples made it much easier to understand.

Cheers

$gt = $genre->implode(' ', 'title');
Link to comment
Share on other sites

To make this fully clear. The implode function you're using is a ProcessWire specific implementation of the php function. The php version does only work on arrays and the array has to be passed into the function as parameter. What you're using is a method of the WireArray class, which mimics a lot of the array features, but adds lot more to it. That's why the syntax is different and therefore the php docs wouldn't help to much.

  • Like 3
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...