Skip to content

Commit 216fe4e

Browse files
authored
[Docs] Customizing page title (#210)
2 parents d34a35b + 79610b9 commit 216fe4e

File tree

14 files changed

+53
-12
lines changed

14 files changed

+53
-12
lines changed

config/packages/sylius_twig_hooks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ sylius_twig_hooks:
4141
title:
4242
template: '@SyliusBootstrapAdminUi/shared/crud/common/content/header/title_block/title.html.twig'
4343
configuration:
44+
title: app.ui.browsing_speakers
4445
icon: tabler:users
4546
subheader: app.ui.managing_your_speakers
10.5 KB
Loading
Loading
11.9 KB
Loading

docs/cookbook/admin_panel/page_titles.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# Customizing the page titles
22

3+
## Changing the default title for a specific page
4+
5+
<div data-full-width="false">
6+
7+
<figure><img src="../../.gitbook/assets/browsing_speakers.png" alt="Title changed to Browsing speakers"></figure>
8+
9+
</div>
10+
11+
By default, each page has a default title based on both page location and resource name.
12+
If you're not happy with the preset title for a specific page and would like to customize it,
13+
you can easily change it using Twig Hooks.
14+
15+
Search for "title_block" in the call graph of the Symfony debug profiler in the `Twig Hooks` section.
16+
17+
<div data-full-width="false">
18+
19+
<figure><img src="../../.gitbook/assets/title_block_in_profiler.png" alt="Title block in profiler"></figure>
20+
21+
</div>
22+
23+
We're going to reuse this hook and its template in our config file and add a `header` key:
24+
25+
```yaml
26+
# config/packages/sylius_bootstrap_admin_ui.yaml
27+
# ...
28+
sylius_twig_hooks:
29+
hooks:
30+
# ...
31+
'sylius_admin.speaker.index.content.header.title_block':
32+
title:
33+
template: '@SyliusBootstrapAdminUi/shared/crud/common/content/header/title_block/title.html.twig'
34+
configuration:
35+
title: app.ui.browsing_speakers # here is our title override
36+
```
37+
338
## Adding an icon
439
540
<div data-full-width="false">
@@ -10,7 +45,8 @@
1045
1146
To add an icon to the page title, you need to use Twig hooks configuration.
1247
13-
Search the "title_block" in the Symfony debug profiler at the Twig hooks section.
48+
Search for "title_block" in the call graph of the Symfony debug profiler in the `Twig Hooks` section.
49+
We're going to reuse this hook and its template in our config file.
1450

1551
<div data-full-width="false">
1652

@@ -79,5 +115,5 @@ sylius_twig_hooks:
79115
# We need to reuse the same template as 'sylius_admin.common.index.content.header.title_block'
80116
template: '@SyliusBootstrapAdminUi/shared/crud/common/content/header/title_block/title.html.twig'
81117
configuration:
82-
subheader: app.ui.managing_your_speakers # you also need add this key on your translations.
118+
subheader: app.ui.managing_your_speakers # you also need to add this key to your translations
83119
```

src/BootstrapAdminUi/templates/shared/helper/header.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{% macro default(level, header, icon, subheader) %}
22
<div class="d-flex gap-3 align-items-center">
33
{% if icon %}
4-
<div>{{ ux_icon(icon, {'class': 'icon icon-md text-primary'}) }}</div>
4+
<div {{ sylius_test_html_attribute('icon', icon) }}>{{ ux_icon(icon, {'class': 'icon icon-md text-primary'}) }}</div>
55
{% endif %}
66
<div class="d-flex flex-column gap-2">
7-
<h{{ level }} class="page-title">
7+
<h{{ level }} class="page-title" {{ sylius_test_html_attribute('page-title') }}>
88
{{ header }}
99
</h{{ level }}>
1010
{% if subheader %}
11-
<div>{{ subheader }}</div>
11+
<div {{ sylius_test_html_attribute('subheader') }}>{{ subheader }}</div>
1212
{% endif %}
1313
</div>
1414
</div>

tests/Functional/BookTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testShowingBook(): void
4646
self::assertResponseIsSuccessful();
4747

4848
// Validate Header
49-
self::assertSelectorTextContains('h1.page-title', 'Shinning');
49+
self::assertSelectorTextContains('[data-test-page-title]', 'Shinning');
5050

5151
// Validate page body
5252
self::assertSelectorTextContains('[data-test-author-name]', 'Stephen King');
@@ -71,7 +71,7 @@ public function testBrowsingBooks(): void
7171
self::assertResponseIsSuccessful();
7272

7373
// Validate Header
74-
self::assertSelectorTextContains('h1.page-title', 'Books');
74+
self::assertSelectorTextContains('[data-test-page-title]', 'Books');
7575
self::assertSelectorExists('a:contains("Create")');
7676

7777
// Validate Custom Twig Hooks

tests/Functional/ConferenceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testBrowsingConferences(): void
5252
self::assertResponseIsSuccessful();
5353

5454
// Validate Header
55-
self::assertSelectorTextContains('h1.page-title', 'Conferences');
55+
self::assertSelectorTextContains('[data-test-page-title]', 'Conferences');
5656
self::assertSelectorExists('a:contains("Create")');
5757

5858
// Validate Table header

tests/Functional/DashboardTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ public function testDashboard(): void
3535

3636
self::assertResponseIsSuccessful();
3737

38-
self::assertSelectorTextContains('h1.page-title', 'Dashboard');
38+
self::assertSelectorTextContains('[data-test-page-title]', 'Dashboard');
3939
}
4040
}

tests/Functional/SpeakerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public function testBrowsingSpeakers(): void
5050
self::assertResponseIsSuccessful();
5151

5252
// Validate Header
53-
self::assertSelectorTextContains('h1.page-title', 'Speakers');
53+
self::assertSelectorTextContains('[data-test-page-title]', 'Browsing speakers');
54+
self::assertSelectorExists('[data-test-icon="tabler:users"]');
55+
self::assertSelectorTextContains('[data-test-subheader]', 'Managing your speakers');
5456
self::assertSelectorExists('a:contains("Create")');
5557

5658
// Validate Table header

tests/Functional/TalkTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testBrowsingTalks(): void
5757
self::assertResponseIsSuccessful();
5858

5959
// Validate Header
60-
self::assertSelectorTextContains('h1.page-title', 'Talks');
60+
self::assertSelectorTextContains('[data-test-page-title]', 'Talks');
6161
self::assertSelectorExists('a:contains("Create")');
6262

6363
// Validate Table header

tests/Translations/FrenchTranslatedUiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testBrowsingItems(): void
7373
self::assertResponseIsSuccessful();
7474

7575
// Validate Header
76-
self::assertSelectorTextContains('h1.page-title', 'Livres');
76+
self::assertSelectorTextContains('[data-test-page-title]', 'Livres');
7777

7878
// Validate Table header
7979
self::assertSelectorTextContains('.sylius-table-column-title', 'Titre');

translations/messages.en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ app:
77
biz: Biz
88
book: Book
99
books: Books
10+
browsing_speakers: Browsing speakers
1011
company_name: Company name
1112
conference: Conference
1213
conferences: Conferences

translations/messages.fr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ app:
77
biz: Biz
88
book: Livre
99
books: Livres
10+
browsing_speakers: Parcourir les Conférencier-e-s
1011
company_name: Société
1112
conference: Conférence
1213
conferences: Conférences

0 commit comments

Comments
 (0)