Skip to content

Commit 39f84c1

Browse files
committed
twig config: test
1 parent a83d791 commit 39f84c1

4 files changed

Lines changed: 35 additions & 11 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ Please install this package via Composer from within the
2727
[phpList base distribution](https://github.com/phpList/base-distribution),
2828
which also has more detailed installation instructions in the README.
2929

30+
When this module is installed as a dependency, publish bundle assets to the host application's `public/` directory:
31+
32+
```bash
33+
php bin/console assets:install public --symlink --relative
34+
```
35+
36+
This module serves its frontend files from `/`.
37+
3038

3139
## Contributing to this package
3240

src/DependencyInjection/PhpListFrontendExtension.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
class PhpListFrontendExtension extends Extension implements PrependExtensionInterface
1616
{
17+
private const TWIG_NAMESPACE = 'PhpListFrontend';
18+
private const ASSET_PACKAGE_NAME = 'phplist_web_frontend';
19+
1720
/**
1821
* Loads a specific configuration.
1922
*
@@ -28,16 +31,33 @@ public function load(array $configs, ContainerBuilder $container): void
2831
{
2932
// @phpstan-ignore-next-line
3033
$configs;
31-
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
34+
$loader = new YamlFileLoader($container, new FileLocator($this->getBundlePath() . '/config'));
3235
$loader->load('services.yml');
3336
}
3437

3538
public function prepend(ContainerBuilder $container): void
3639
{
40+
$bundlePath = $this->getBundlePath();
41+
3742
$container->prependExtensionConfig('twig', [
3843
'paths' => [
39-
__DIR__ . '/../../templates' => 'PhpListFrontend',
44+
$bundlePath . '/templates' => self::TWIG_NAMESPACE,
45+
],
46+
]);
47+
48+
$container->prependExtensionConfig('framework', [
49+
'assets' => [
50+
'packages' => [
51+
self::ASSET_PACKAGE_NAME => [
52+
'base_path' => '/',
53+
],
54+
],
4055
],
4156
]);
4257
}
58+
59+
private function getBundlePath(): string
60+
{
61+
return dirname(__DIR__, 2);
62+
}
4363
}

templates/auth/login.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="bg-gray-200">
88
<div class="min-h-screen flex flex-col items-center justify-center">
99
<div class="flex items-center mb-6">
10-
<img src="{{ asset('/favicon-48.png') }}" alt="phpList icon" width="40" height="40" class="mr-2"/>
10+
<img src="{{ asset('favicon-48.png', 'phplist_web_frontend') }}" alt="phpList icon" width="40" height="40" class="mr-2"/>
1111
<h1 class="text-xl font-bold mb-0">
1212
phpList <span class="text-ext-wf1">4</span>
1313
</h1>

templates/base.html.twig

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@
44
<meta charset="UTF-8">
55
<title>{% block title %}phpList{% endblock %}</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7-
{# <script src="https://cdn.tailwindcss.com"></script>#}
8-
<link rel="stylesheet" href="{{ asset('build/app.css') }}">
9-
{# Add your own custom CSS later if needed #}
10-
{{ encore_entry_link_tags('styles') }}
7+
<link rel="stylesheet" href="{{ asset('build/app.css', 'phplist_web_frontend') }}">
8+
<link rel="stylesheet" href="{{ asset('build/styles.css', 'phplist_web_frontend') }}">
119

1210
{% block javascripts %}
13-
{{ encore_entry_script_tags('app') }}
11+
<script src="{{ asset('build/runtime.js', 'phplist_web_frontend') }}" defer></script>
12+
<script src="{{ asset('build/app.js', 'phplist_web_frontend') }}" defer></script>
1413
{% endblock %}
1514
</head>
1615
<body>
1716
<main class="">
1817
{% block body %}{% endblock %}
1918
</main>
20-
21-
<script src="{{ asset('build/runtime.js') }}"></script>
22-
<script src="{{ asset('build/app.js') }}"></script>
2319
</body>
2420
</html>

0 commit comments

Comments
 (0)