Skip to content

Commit

Permalink
Merge pull request #108 from IvoElgentos/add-iterator-to-prismic-block
Browse files Browse the repository at this point in the history
add array key to prismic block
  • Loading branch information
WouterSteen committed Nov 20, 2023
2 parents 0934761 + aec6eab commit 0827e46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Block/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ public function fetchDocumentView(): string
}

$html = '';
foreach ($items as $item) {
$html .= $this->fetchItem($item);
foreach ($items as $key => $item) {
$html .= $this->fetchItem($item, $key);
}

return $html;
}

public function fetchItem(\stdClass $item): string
public function fetchItem(\stdClass $item, $key = null): string
{
$childNames = $this->getChildNames();

$html = '';
foreach ($childNames as $childName) {
$itemBlock = $this->getChildBlock($childName);
$itemBlock->setDocument($item);
if (null !== $key) {
$itemBlock->setIterator($key);
}

$html .= $itemBlock->toHtml();
}
Expand Down
2 changes: 1 addition & 1 deletion Block/Slices.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Slices extends Group
{
public function fetchItem(\stdClass $slice): string
public function fetchItem(\stdClass $slice, $key = null): string
{
$sliceTypeBlock = $this->getSliceTypeBlock($slice->slice_type);
if (null === $sliceTypeBlock) {
Expand Down

0 comments on commit 0827e46

Please sign in to comment.