Working with Blade (Laravel template engine), I have two layouts:
-
guest.blade.php, for guest related stuff (login, password request, etc.). Basically it's a slim template where content is centered (mostly forms)
-
auth.blade.php, for authenticated users stuff (you know, the full layout with header, sidebar, etc.)
These two layouts have the following features (please sit down before having a headache :-) ):
- They share some common CSS and JS (bootstrap, font-awesome, jquery, etc.) in two different partials (
css.blade.php in the document head and js.blade.php at the bottom).
- The
auth.blade.php has obviously additional assets that aren't useful in slimmer guest.blade.php but are required in (mostly) ALL of the auth pages (select2, jquery-ui, etc.).
Yes, I could put these additional CSS' and JS' in previously mentioned css.blade.php and js.blade.php and have them all in one file, but they would bloat guest.blade.php that I'd like to keep slim.
And of course I don't want to put them in every child view! :-)
- Some views (both auth and guest related) could ask for peculiar assets just for that view: a dashboard could require some charts assets, a media manager could require multi-uploader assets, a login page could require a CSS or JS just for that login view.
- Last but not least, the order in which assets are loaded is important: i.e. for CSS
- global_mandatory_styles (bootstrap, font-awesome, etc.)
- global_mandatory_styles_addition (only for auth template)
- page_levels_plugins (peculiar css plugin for the current view*)
- theme_global_styles (mostly components)
- page_level_styles (peculiar css custom styles for the current view**)
- theme_layout_styles (the global styles and the "skin": blue, green, etc.)
- my_custom_style
This order is what premium admin template Metronic 4.7.* comes with (I'll be using that), with the exclusion of "global_mandatory_styles_addition" and "my_custom_style" that I added on my own: I guess this loading order is mandatory.
Just to have an idea, take a look at these pages (each section I mentioned above has a START and END comment so you can easily locate; the same goes for JS but let's focus on CSS):
Summing, the goal is to keep one single css.blade.php for both guest.blade.php and auth.blade.php (1), add the shared auth assets when using the auth template (2), and being able to set custom assets per-view, equally when using guest and auth template (3) - and the same goes for javascript assets
* css plugins are mostly retrieved from cdn
** these are additional custom made styles only for that view, often an override of the cdn retrieved plugins
Oh, really I think I did, but don't know if it's the right approach since it seems a strange use of @push and @stack and I'd like to know if there's a cleaner solution
layouts.guest.blade.php
...
@include('partials.css')
...
layouts.auth.blade.php
@include('partials.stack') {{-- on top of the page --}}
...
@include('partials.css')
...
partials.css.blade.php
<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="cdn/bootstrap.css">
<link href="cdn/font-awesome.css">
<!-- END GLOBAL MANDATORY STYLES -->
<!-- BEGIN GLOBAL MANDATORY STYLES, AUTH ONLY -->
@stack('shared-auth')
<!-- END GLOBAL MANDATORY STYLES, AUTH ONLY -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
@stack('css-plugins')
<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN THEME GLOBAL STYLES -->
<link href="metronic/components.css">
<link href="metronic/plugins.css">
<!-- END THEME GLOBAL STYLES -->
<!-- BEGIN PAGE LEVEL STYLES -->
@stack('css-styles')
<!-- BEGIN PAGE LEVEL STYLES -->
<!-- BEGIN THEME LAYOUT STYLES, AUTH ONLY -->
@stack('theme')
<!-- END THEME LAYOUT STYLES, AUTH ONLY -->
<!-- BEGIN MY STYLES -->
<link href="custom/style.css">
<!-- BEGIN MY STYLES -->
partials.stack.blade.php (remember, this goes only on top of auth layout, so it contains the auth shared assets)
@push('shared-auth')
<link href="cdn/jquery-ui.css">
<link href="cdn/select2.css">
@endpush
@push('theme')
<link href="metronic/darkblue.css">
@endpush
dashboard.blade.php
@push('css-plugins')
<link href="cdn/morris.css">
<link href="cdn/fullcalendar.css">
@endpush
@push('css-styles')
<link ="metronic/morris-override.css">
@endpush
login.blade.php
@push('css-plugins')
<link href="cdn/icheck-blue.css">
@endpush
@push('css-styles')
<link href="metronic/login-style.css">
@endpush
Does it makes sense? The weird part to me is the @include('partials.stack') on top of layouts.auth.blade.php that pushes to the @stack of the other included file @include('partials.css')
It seems to me an uncommon (and undocumented, as far as I googled...) use of @push and @stack: are there better and recommended alternatives?