Skip to content

Commit 4c6ef7b

Browse files
committed
twig config: test
1 parent a83d791 commit 4c6ef7b

4 files changed

Lines changed: 36 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 `/bundles/phplistfrontend`.
37+
3038

3139
## Contributing to this package
3240

src/DependencyInjection/PhpListFrontendExtension.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
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+
private const ASSET_BASE_PATH = '/bundles/phplistfrontend';
20+
1721
/**
1822
* Loads a specific configuration.
1923
*
@@ -28,16 +32,33 @@ public function load(array $configs, ContainerBuilder $container): void
2832
{
2933
// @phpstan-ignore-next-line
3034
$configs;
31-
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
35+
$loader = new YamlFileLoader($container, new FileLocator($this->getBundlePath() . '/config'));
3236
$loader->load('services.yml');
3337
}
3438

3539
public function prepend(ContainerBuilder $container): void
3640
{
41+
$bundlePath = $this->getBundlePath();
42+
3743
$container->prependExtensionConfig('twig', [
3844
'paths' => [
39-
__DIR__ . '/../../templates' => 'PhpListFrontend',
45+
$bundlePath . '/templates' => self::TWIG_NAMESPACE,
46+
],
47+
]);
48+
49+
$container->prependExtensionConfig('framework', [
50+
'assets' => [
51+
'packages' => [
52+
self::ASSET_PACKAGE_NAME => [
53+
'base_path' => self::ASSET_BASE_PATH,
54+
],
55+
],
4056
],
4157
]);
4258
}
59+
60+
private function getBundlePath(): string
61+
{
62+
return dirname(__DIR__, 2);
63+
}
4364
}

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)