Skip to content

Commit 1747ef5

Browse files
authored
Merge pull request #119 from davysumo/replace-source-function-with-custom
ContentExtension
2 parents 33ed6ca + 0d9cf0e commit 1747ef5

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

config/services.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use App\Twig\ContentExtension;
56
use SumoCoders\FrameworkCoreBundle\Command\TranslateCommand;
67
use Symfony\Component\Form\Extension\Core\Type\TimeType;
78
use SumoCoders\FrameworkCoreBundle\Service\Fallbacks;
@@ -101,6 +102,9 @@
101102
->set('framework.paginator_runtime', PaginatorRuntime::class)
102103
->tag('twig.runtime')
103104

105+
->set('framework.content_extension', ContentExtension::class)
106+
->tag('twig.extension')
107+
104108
/*
105109
* Breadcrumbs
106110
*/

src/Twig/ContentExtension.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Twig;
4+
5+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
6+
use Twig\Extension\AbstractExtension;
7+
use Twig\TwigFunction;
8+
9+
class ContentExtension extends AbstractExtension
10+
{
11+
public function __construct(
12+
#[Autowire('%kernel.project_dir%/public')]
13+
private string $publicFolder
14+
) {
15+
}
16+
17+
public function getFunctions(): array
18+
{
19+
return [
20+
new TwigFunction('content', [$this, 'getContent'], ['is_safe' => ['html']]),
21+
];
22+
}
23+
24+
public function getContent(string $path): string
25+
{
26+
return file_get_contents($this->publicFolder . $path);
27+
}
28+
}

templates/Mail/base.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% apply inky_to_html|inline_css(source(asset('build/mail.css'))) %}
1+
{% apply inky_to_html|inline_css(content(asset('build/mail.css'))) %}
22
<spacer size="16"></spacer>
33
<container>
44
<spacer size="16"></spacer>

0 commit comments

Comments
 (0)