Skip to content

Commit

Permalink
Fix adding attributes to self-closing controlled component's, update …
Browse files Browse the repository at this point in the history
…documentation
  • Loading branch information
dgvirtual committed Jan 10, 2025
1 parent d27d033 commit aa3464e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions docs/building_sites/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ in the following output:
/>
```

## Custom Tags
## Tags With Content

You can include the content within the opening and closing tags by inserting the reserved `$slot` variable:

Expand All @@ -61,10 +61,14 @@ You can include the content within the opening and closing tags by inserting the

## Controlled Components

Finally, you can create a class to add additional logic to the output. The file must be in the same directory
as the component view, and should have a name that is the PascalCase version of the filename, with 'Component'
added to the end of it.
Finally, you can create a class to add additional logic to the output for both self-closing tags and tags
with content. The file must be in the same directory as the component view, and should have a name that is
the PascalCase version of the filename, with 'Component' added to the end of it. Any attributes that you
set on the custom element and any content within element will be passed to the class of the controlled
component to be, optionally, processed by the component class and/or rendered by the comonent view file.
The data you pass will be available within the class as it's `$data` property (the tag content – as
`$data['slot']` property).

A `famous-qoutes` component would have a view called `famous-quotes.php` and a controlling class called
`FamousQuotesComponent.php`. The class must extend `Bonfire\View\Component`. The only requirement is that you
implment a method called `render()`.
`FamousQuotesComponent.php`. The class must extend `Bonfire\View\Component`. The only requirement is that you
implement a method called `render()`.
2 changes: 1 addition & 1 deletion src/View/ComponentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private function renderSelfClosingTags(string $output): string
$component = $this->factory($match['name'], $view);

return $component instanceof Component
? $component->withView($view)->render()
? $component->withView($view)->withData($attributes)->render()
: $this->renderView($view, $attributes);
}, $output);
}
Expand Down

0 comments on commit aa3464e

Please sign in to comment.