PHP code example of jascha030 / wp-sequoia

1. Go to this page and download the library: Download jascha030/wp-sequoia 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/ */

    

jascha030 / wp-sequoia example snippets




use Jascha030\Sequoia\Templater\TwigTemplater;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

// Replace with the path to your templates folder.
$loader      = new FilesystemLoader('/Twig/Template/Folder');
$environment = new Environment($loader);
$templater = new TwigTemplater($environment);


 

namespace Example\Component;

use Jascha030\Sequoia\Component\TwigComponentAbstract;

final class ListComponent extends TwigComponentAbstract 
{
    /**
     * @inheritDoc
     */
    public function getTemplate(): string
    {
        return 'list-template.twig';
    }
}




use Example\Component\ListComponent;
use Jascha030\Sequoia\Templater\TwigTemplater;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

// Replace with the path to your templates folder.
$loader      = new FilesystemLoader('/Twig/Template/Folder');
$environment = new Environment($loader);
$templater = new TwigTemplater($environment);

ListComponent::render(
    $templater, 
    [
        'items' => [
            ['text' => 'List item 1'],
            ['text' => 'List item 2']
        ]
    ]
);


…

final class ListComponent extends TwigComponentAbstract 
{
    use HasDefaultContextTrait;
    
    /**
     * @inheritDoc
     */
    public function getTemplate(): string
    {
        return 'list-template.twig';
    }
    
    /**
     * @inheritDoc
     */
    final public function getDefaults(): array
    {
        return [
            'items' => [
                ['text' => 'List item 1'],
                ['text' => 'List item 2']
            ]
        ];
    }
}



function edit_list_items(array $context): array
{
    $context['items'][] = ['text' => 'List item 3'];
    
    return $context;
}

\add_filter('twig_template_context_list-template', 'edit_list_items');