diff --git a/config/hyde.php b/config/hyde.php index 89681ead..9cbbe1cc 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -224,6 +224,23 @@ Meta::property('site_name', env('SITE_NAME', 'HydePHP')), ], + /* + |-------------------------------------------------------------------------- + | Custom head and script HTML hooks + |-------------------------------------------------------------------------- + | + | While the best way to add custom `` and `` code is to use the + | Blade components, you can also add them here. This is useful for adding + | scripts like analytics codes, chat widgets, or even custom styles. + | + */ + + // Add any extra HTML to include in the tag + 'head' => '', + + // Add any extra HTML to include before the closing tag + 'scripts' => '', + /* |-------------------------------------------------------------------------- | Features diff --git a/resources/views/layouts/head.blade.php b/resources/views/layouts/head.blade.php index 50370598..69097ab8 100644 --- a/resources/views/layouts/head.blade.php +++ b/resources/views/layouts/head.blade.php @@ -16,4 +16,7 @@ {{-- Check the local storage for theme preference to avoid FOUC --}} -@endif \ No newline at end of file +@endif + +{{-- If the user has defined any custom head tags, render them here --}} +{!! config('hyde.head') !!} \ No newline at end of file diff --git a/resources/views/layouts/scripts.blade.php b/resources/views/layouts/scripts.blade.php index 3b892867..749d887d 100644 --- a/resources/views/layouts/scripts.blade.php +++ b/resources/views/layouts/scripts.blade.php @@ -21,4 +21,7 @@ function toggleTheme() { {{-- Add any extra scripts to include before the closing tag --}} -@stack('scripts') \ No newline at end of file +@stack('scripts') + +{{-- If the user has defined any custom scripts, render them here --}} +{!! config('hyde.scripts') !!} diff --git a/tests/Unit/Views/HeadComponentViewTest.php b/tests/Unit/Views/HeadComponentViewTest.php index fd8935f9..e89bcf35 100644 --- a/tests/Unit/Views/HeadComponentViewTest.php +++ b/tests/Unit/Views/HeadComponentViewTest.php @@ -72,6 +72,13 @@ public function testComponentIncludesStylesView() $this->assertStringContainsString("@include('hyde::layouts.styles')", $this->renderTestView()); } + public function testCanAddHeadHtmlFromConfigHook() + { + config(['hyde.head' => '']); + + $this->assertStringContainsString('', $this->renderTestView()); + } + protected function escapeIncludes(string $contents): string { return str_replace('@include', '@@include', $contents); diff --git a/tests/Unit/Views/ScriptsComponentViewTest.php b/tests/Unit/Views/ScriptsComponentViewTest.php index 15df7638..498efc4f 100644 --- a/tests/Unit/Views/ScriptsComponentViewTest.php +++ b/tests/Unit/Views/ScriptsComponentViewTest.php @@ -56,6 +56,13 @@ public function test_component_uses_relative_path_to_app_js_file_for_nested_page Filesystem::unlink('_media/app.js'); } + public function testCanAddHeadHtmlFromConfigHook() + { + config(['hyde.scripts' => '']); + + $this->assertStringContainsString('', $this->renderTestView()); + } + public function test_scripts_can_be_pushed_to_the_component_scripts_stack() { view()->share('routeKey', '');