-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 visuellverstehen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,72 @@ | ||
# Statamic Content Renderer | ||
# Content Renderer | ||
|
||
> Statamic Content Renderer is a Statamic addon that does something pretty neat. | ||
## Features | ||
|
||
This addon does: | ||
|
||
- This | ||
- And this | ||
- And even this | ||
A Statamic addon that renders content from bard and replicator fields to make their content searchable with [search transformers](https://statamic.dev/search#transforming-fields). | ||
|
||
## How to Install | ||
|
||
You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root: | ||
Run the following command from your project root: | ||
|
||
``` bash | ||
composer require visuellverstehen/statamic-content-renderer | ||
``` | ||
|
||
## How to Use | ||
|
||
Here's where you can explain how to use this wonderful addon. | ||
The content renderer is available through the `Renderer()` class. To render the content of a replicator or bard field, the class requires a view that provides the info of how to display all the configured sets, e. g.: | ||
|
||
```antlers | ||
{{# resources/views/sets.antlers.php #}} | ||
{{ my_replicator_field }} | ||
{{ partial src="sets/{type}" }} | ||
{{ /my_replicator_field }} | ||
``` | ||
|
||
This view needs to be passed on to the renderer class. | ||
|
||
```php | ||
use VV\ContentRenderer\Renderer; | ||
|
||
// ... | ||
|
||
$renderer = new Renderer(); | ||
$renderer->setContent($entry, 'my_replicator_field'); | ||
$renderer->setView('sets'); | ||
|
||
$content = $renderer->render(); | ||
``` | ||
|
||
The renderer uses the view to render all sets (and all written content of bard fields), sanitizes the content (strips all HTML tags etc.) and returns a string containing every written word from within the field. | ||
|
||
This can be used within a [search transformer](https://statamic.dev/search#transforming-fields) to make the content of bard and replicator fields available for full-text search: | ||
|
||
```php | ||
namespace App\SearchTransformers; | ||
|
||
use VV\ContentRenderer\Renderer; | ||
|
||
class MyReplicatorFieldTransformer | ||
{ | ||
public function handle($value, $field, $searchable) | ||
{ | ||
$renderer = new Renderer(); | ||
$renderer->setContent($searchable, 'my_replicator_field'); | ||
$renderer->setView('sets'); | ||
|
||
return $renderer->render(); | ||
} | ||
} | ||
``` | ||
|
||
If you want to keep the HTML tags and/or modify the content in your own way, you can instruct the renderer to keep them: | ||
|
||
```php | ||
$renderer = (new Renderer())->withHtmlTags(); | ||
``` | ||
|
||
## More about us | ||
|
||
- [www.visuellverstehen.de](https://visuellverstehen.de) | ||
|
||
## License | ||
The MIT license (MIT). Please take a look at the [license file](LICENSE.md) for more information. |