PageArray/WireArray


Getting Items

$a->and($item | $items)

Introduced in Version 2.4

Description

Return a new copy of the WireArray with the given item or items appended.

Primarily intended as a syntax convenience for various situations. This is similar to jQuery's add() and andSelf() functions, but we felt "add" implied adding something to the original rather than creating a new combination, so went with "and" in this case. 

Usage:

// create a new WireArray with $items and $item (appended)
$myItems = $items->and($item); 

// create a new WireArray with $items and $moreItems (appended)
$myItems = $items->and($moreItems); 

// create a new WireArray with $items and $item (prepended)
$myItems = $item->and($items); 

// create a new WireArray with $item and $anotherItem (appended)
$myItems = $item->and($anotherItem); 

// create a new WireArray 4 items
$family = $pappa->and($mamma)->and($brother)->and($sister); 

Examples:

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

// check if page or its children has a featured checkbox
if($page->and($page->children)->has("featured=1")) {
  echo "<p>Featured!</p>";
}


Related

Post Comment