Skip to content

Commit 7311f97

Browse files
authored
Add metatags hook (favicon, seo, etc.) (#275)
This pull request adds: * a hook for adding metatags * documentation for the hook Solves #274
2 parents 6d4728d + e02a18f commit 7311f97

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

docs/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [Customizing the menu](cookbook/admin_panel/menu.md)
1313
* [Configuring the security access](cookbook/admin_panel/security.md)
1414
* [Customizing the page titles](cookbook/admin_panel/page_titles.md)
15+
* [Customizing the metatags](cookbook/admin_panel/metatags.md)
1516
* [How to use in a DDD architecture](cookbook/ddd_architecture.md)
1617
* [Architecture overview](cookbook/ddd_architecture/overview.md)
1718
* [Resource configuration](cookbook/ddd_architecture/resource_configuration.md)

docs/cookbook/admin_panel.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
* [Customizing the menu](admin_panel/menu.md)
77
* [Configuring the security access](admin_panel/security.md)
88
* [Customizing the page titles](admin_panel/page_titles.md)
9+
* [Customizing the metatags](admin_panel/metatags.md)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Customizing the metatags
2+
3+
## Adding metatags
4+
5+
To add new `<head>` meta tags, you can use the `sylius_admin#metatags` hook. This is useful for adding a favicon or SEO meta tags, for example.
6+
You can register your own Twig template for meta tags via YAML or PHP.
7+
8+
{% tabs %}
9+
{% tab title="YAML" %}
10+
{% code title="config/packages/sylius_bootstrap_admin_ui.yaml" lineNumbers="true" %}
11+
```yaml
12+
# ...
13+
sylius_twig_hooks:
14+
hooks:
15+
# ...
16+
'sylius_admin.base#metatags':
17+
favicon:
18+
template: 'favicon.html.twig'
19+
seo_metatags:
20+
template: 'seo_metatags.html.twig'
21+
```
22+
{% endcode %}
23+
{% endtab %}
24+
25+
{% tab title="PHP" %}
26+
{% code title="config/packages/sylius_bootstrap_admin_ui.php" lineNumbers="true" %}
27+
```php
28+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
29+
30+
return static function (ContainerConfigurator $containerConfigurator): void {
31+
// ...
32+
33+
// Define your own Twig template for the favicon.
34+
$containerConfigurator->extension('sylius_twig_hooks', [
35+
'hooks' => [
36+
'sylius_admin.base#metatags' => [
37+
'favicon' => [
38+
'template' => 'favicon.html.twig',
39+
],
40+
'seo_metatags' => [
41+
'template' => 'seo_metatags.html.twig',
42+
],
43+
],
44+
],
45+
46+
]);
47+
};
48+
```
49+
{% endcode %}
50+
{% endtab %}
51+
{% endtabs %}

src/AdminUi/templates/base.html.twig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
<title>{% block title %}{% apply striptags %}{% hook generic_hook ~ '#base_title' %}{% endapply %}{% endblock %}</title>
1111

12-
{% block metatags %}{% endblock %}
12+
{% block metatags %}
13+
{% hook generic_hook ~ '#metatags' %}
14+
{% endblock %}
15+
1316
{% block stylesheets %}
1417
{% hook generic_hook ~ '#stylesheets' %}
1518
{% endblock %}

0 commit comments

Comments
 (0)