Skip to content

Latest commit

 

History

History
46 lines (39 loc) · 1.08 KB

2021-09-28-seourl-twig-factory.md

File metadata and controls

46 lines (39 loc) · 1.08 KB
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: bjoern.herzke@brandung.de                   
author_github: @wrongspot
---

Core

  • Added new class src/Core/Content/Seo/SeoUrlTwigFactory.php

Upgrade Information

Create own SeoUrl Twig Extension

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>