Hans0L0

Intermediate site profile: 'foreach' combined with 'and'?

Recommended Posts

Hi,

I'm new to Processwire and it's been quite a while since my last programming experiences with PHP.
Currently I'm trying to read through the different site profile versions and stumbled over some code construct in the '_main.php' of the intermediate profile which I've never seen before:

foreach($homepage->and($homepage->children) as $item)

To me, it looks like 'and()' is used as a method of object '$homepage' in this case but in combination with the 'foreach'-part I don't understand what exactly is happening here and why this is possible.

I hope that someone can explain it to me on a basic level :)

Thanks in advance

Hans

Share this post


Link to post
Share on other sites

The second-last example explains it quite well:

// generate breadcrumb trail that includes current page
foreach($page->parents->and($page) as $item) {
  echo "<a href='$item->url'>$item->title</a> / ";
}

 

  • Like 2

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.