PHP code example of php-collective / symfony-djot

1. Go to this page and download the library: Download php-collective/symfony-djot 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/ */

    

php-collective / symfony-djot example snippets


use PhpCollective\SymfonyDjot\Service\DjotConverterInterface;

class ArticleController
{
    public function show(DjotConverterInterface $djot): Response
    {
        $html = $djot->toHtml($article->body);
        $text = $djot->toText($article->body);
    }
}

public function __construct(
    // Default converter (safe mode enabled)
    private DjotConverterInterface $djot,

    // Trusted converter (safe mode disabled)
    #[Autowire(service: 'symfony_djot.converter.trusted')]
    private DjotConverterInterface $trusted,
) {}

use PhpCollective\SymfonyDjot\Form\Type\DjotType;

$builder->add('body', DjotType::class);

use PhpCollective\SymfonyDjot\Validator\Constraints\ValidDjot;

class Article
{
    #[ValidDjot]
    private string $body;
}
bash
composer