PHP code example of visuellverstehen / statamic-content-renderer

1. Go to this page and download the library: Download visuellverstehen/statamic-content-renderer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

visuellverstehen / statamic-content-renderer example snippets


use VV\ContentRenderer\Renderer;

// ...

$renderer = new Renderer();
$renderer->setContent($entry, 'my_replicator_field');
$renderer->setView('sets');

$content = $renderer->render();

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();
    }
}

$renderer = (new Renderer())->withLinkTargets();

// read more <a href="https://visuellverstehen.de">about the author</a> of this package
// becomes: read more about the author (https://visuellverstehen.de) of this package

$renderer = (new Renderer())->withHtmlTags();

$renderer = new Renderer();
$renderer->setContent($searchable, 'bard_content');
// …

$renderer->process(function ($content) {
    // modify content
    
    return $content;
});

$renderer = new Renderer();
$renderer->setValue($fieldValue);

$content = $renderer->render();

// This works the same in v1.x and v2.x
$renderer->process(function ($content) {
    return array_filter($content, fn ($item) => ($item['type'] ?? null) !== 'set');
});

// v1.x - values were processed
$renderer->process(function ($content) {
    // $content[0]['text'] was already processed as a Text fieldtype value
});

// v2.x - values are raw
$renderer->process(function ($content) {
    // $content[0]['text'] is the raw string value from the entry
});