Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 5 column 16
---
title: Factory to build Seo Url Twig Environment
issue: NEXT-17849
author: Björn Herzke
author_email: [email protected]
author_github: @wrongspot
---
- Added new class
src/Core/Content/Seo/SeoUrlTwigFactory.php
Create a regular Twig extension, instead of tagging it with name twig.extension
use tag name shopware.seo_url.twig.extension
Example Class:
<?php declare(strict_types=1);
namespace SwagExample\Core\Content\Seo\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class ExampleTwigFilter extends AbstractExtension
{
public function getFilters(): array
{
return [
new TwigFilter('lastBigLetter', [$this, 'convert']),
];
}
public function convert(string $text): string
{
return strrev(ucfirst(strrev($text)));
}
}
Example service.xml:
<service id="SwagExample\Core\Content\Seo\Twig\ExampleTwigFilter">
<tag name="shopware.seo_url.twig.extension"/>
</service>