diff --git a/README.md b/README.md index 01125d0..ad52220 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ $this->Htmx->addBlock('userTable'); The `addBlocks()` function allows you to add multiple blocks to the list of blocks that should be rendered ```php $this->Htmx->addBlocks(['userTable', 'pagination']); +$this->Htmx->addBlocks(['userTable', 'pagination'], true); // Appends the blocks to the existing array. ``` ### OOB Swap diff --git a/src/Controller/Component/HtmxComponent.php b/src/Controller/Component/HtmxComponent.php index b7eff5b..95019df 100644 --- a/src/Controller/Component/HtmxComponent.php +++ b/src/Controller/Component/HtmxComponent.php @@ -417,11 +417,16 @@ public function addBlock(string $block): static /** * Add blocks to render * - * @param array $block List of block names to render + * @param array $blocks List of block names to render + * @param bool $append Whether to append the blocks or replace existing ones */ - public function addBlocks(array $block): static + public function addBlocks(array $blocks, bool $append = false): static { - $this->blocks[] = $block; + if ($append) { + $this->blocks = array_merge($this->blocks, $blocks); + } else { + $this->blocks = $blocks; + } return $this; }