Skip to content

Commit 7676ac9

Browse files
authored
Merge pull request #1554 from hydephp/improved-head-and-scripts-includes
Support using HTML includes to set head and script HTML
2 parents a5b9df8 + f1447c1 commit 7676ac9

File tree

6 files changed

+21
-2
lines changed

6 files changed

+21
-2
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This serves two purposes:
2222
### Added
2323
- Added the existing `media_extensions` option to the `hyde` configuration file in https://github.com/hydephp/develop/pull/1531
2424
- Added configuration options to add custom HTML to the `<head>` and `<script>` sections in https://github.com/hydephp/develop/pull/1542
25+
- Added support for adding custom HTML to the `<head>` and `<script>` sections using HTML includes in https://github.com/hydephp/develop/pull/1554
2526
- Added an `html` helper to the `Includes` facade in https://github.com/hydephp/develop/pull/1552
2627

2728
### Changed

docs/digging-deeper/helpers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Includes::markdown('example.md', 'Default content');
8787
HydePHP also supports some drop-in includes that you can use as an alternative to some config options. These currently are as follows:
8888

8989
- `footer` If a `footer.md` file exists in the includes directory, Hyde will use that as the footer text, instead of the one set in the `hyde.footer` config option.
90+
- 'head' If a `head.html` file exists in the includes directory, Hyde include that within the `<head>` tag of the generated HTML, in addition to the one set in the `hyde.head` config option.
91+
- 'scripts' If a `scripts.html` file exists in the includes directory, Hyde include that at the end of the `<body>` tag of the generated HTML, in addition to the one set in the `hyde.scripts` config option.
9092

9193

9294
## Reading time helper

packages/framework/resources/views/layouts/head.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
@endif
2020

2121
{{-- If the user has defined any custom head tags, render them here --}}
22-
{!! config('hyde.head') !!}
22+
{!! config('hyde.head') !!}
23+
{!! Includes::html('head') !!}

packages/framework/resources/views/layouts/scripts.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ function toggleTheme() {
2525

2626
{{-- If the user has defined any custom scripts, render them here --}}
2727
{!! config('hyde.scripts') !!}
28+
{!! Includes::html('scripts') !!}

packages/framework/tests/Unit/Views/HeadComponentViewTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public function testCanAddHeadHtmlFromConfigHook()
7979
$this->assertStringContainsString('<meta name="custom-hook" content="foo">', $this->renderTestView());
8080
}
8181

82+
public function testCanAddHeadHtmlFromHtmlInclude()
83+
{
84+
$this->file('resources/includes/head.html', '<meta name="custom-include" content="foo">');
85+
86+
$this->assertStringContainsString('<meta name="custom-include" content="foo">', $this->renderTestView());
87+
}
88+
8289
protected function escapeIncludes(string $contents): string
8390
{
8491
return str_replace('@include', '@@include', $contents);

packages/framework/tests/Unit/Views/ScriptsComponentViewTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,20 @@ public function test_component_uses_relative_path_to_app_js_file_for_nested_page
5656
Filesystem::unlink('_media/app.js');
5757
}
5858

59-
public function testCanAddHeadHtmlFromConfigHook()
59+
public function testCanAddScriptsHtmlFromConfigHook()
6060
{
6161
config(['hyde.scripts' => '<script src="custom-hook.js"></script>']);
6262

6363
$this->assertStringContainsString('<script src="custom-hook.js"></script>', $this->renderTestView());
6464
}
6565

66+
public function testCanAddScriptsHtmlFromHtmlInclude()
67+
{
68+
$this->file('resources/includes/scripts.html', '<script src="html-include.js"></script>');
69+
70+
$this->assertStringContainsString('<script src="html-include.js"></script>', $this->renderTestView());
71+
}
72+
6673
public function test_scripts_can_be_pushed_to_the_component_scripts_stack()
6774
{
6875
view()->share('routeKey', '');

0 commit comments

Comments
 (0)