08-18-2016, 05:12 AM
I have some CSS that was very specific to a given page and I didn't want to bother loading for every single page.
I found it difficult to get it into the header portion using the standard UserSpice.
I made this modification, as defined by this patch file. This allows a CSS file with the same name as the current PHP script to be loaded automatically. It also allows for the array $HeaderStyles to be initialized before including header.php and the styles will be included in the <-head->...</-head-> section.
===(snip)===
*** UserSpice41/users/includes/header.php 2016-08-15 15:51:52.791690800 +0200
--- imok/users/includes/header.php 2016-08-15 15:49:49.528667200 +0200
***************
*** 82,92 ****
--- 82,111 ----
<!-- AKA Secondary CSS -->
<link href="<?=$us_url_root?><?=str_replace('../','',$settings->us_css2);?>" rel="stylesheet">
+ <!-- If you are loading xyz.php and a script xyz.css exists, load it !-->
+ <?php
+ $mycss = $us_url_root.'usersc/css/'.basename($_SERVER['PHP_SELF'], '.php').'.css';
+ #echo "mycss=$mycss abs_us_root=$abs_us_root<br />\n";
+ if (file_exists($abs_us_root.$mycss)) {
+ echo "<link href=\"$mycss\" rel=\"stylesheet\">\n";
+ }
+ ?>
+
<!-- Your Custom CSS Goes Here!-->
<link href="<?=$us_url_root?><?=str_replace('../','',$settings->us_css3);?>" rel="stylesheet">
<!-- Custom Fonts -->
<link href="<?=$us_url_root?>users/fonts/css/font-awesome.min.css" rel="stylesheet" type="text/css">
+
+ <!-- Custom inline styles !-->
+ <?php
+ if (@$HeaderStyles) {
+ echo "<style>\n";
+ foreach ((array)$HeaderStyles as $style)
+ echo "$style\n";
+ echo "</style>\n";
+ }
+ ?>
</head>
<body>
===(snip)===
I found it difficult to get it into the header portion using the standard UserSpice.
I made this modification, as defined by this patch file. This allows a CSS file with the same name as the current PHP script to be loaded automatically. It also allows for the array $HeaderStyles to be initialized before including header.php and the styles will be included in the <-head->...</-head-> section.
===(snip)===
*** UserSpice41/users/includes/header.php 2016-08-15 15:51:52.791690800 +0200
--- imok/users/includes/header.php 2016-08-15 15:49:49.528667200 +0200
***************
*** 82,92 ****
--- 82,111 ----
<!-- AKA Secondary CSS -->
<link href="<?=$us_url_root?><?=str_replace('../','',$settings->us_css2);?>" rel="stylesheet">
+ <!-- If you are loading xyz.php and a script xyz.css exists, load it !-->
+ <?php
+ $mycss = $us_url_root.'usersc/css/'.basename($_SERVER['PHP_SELF'], '.php').'.css';
+ #echo "mycss=$mycss abs_us_root=$abs_us_root<br />\n";
+ if (file_exists($abs_us_root.$mycss)) {
+ echo "<link href=\"$mycss\" rel=\"stylesheet\">\n";
+ }
+ ?>
+
<!-- Your Custom CSS Goes Here!-->
<link href="<?=$us_url_root?><?=str_replace('../','',$settings->us_css3);?>" rel="stylesheet">
<!-- Custom Fonts -->
<link href="<?=$us_url_root?>users/fonts/css/font-awesome.min.css" rel="stylesheet" type="text/css">
+
+ <!-- Custom inline styles !-->
+ <?php
+ if (@$HeaderStyles) {
+ echo "<style>\n";
+ foreach ((array)$HeaderStyles as $style)
+ echo "$style\n";
+ echo "</style>\n";
+ }
+ ?>
</head>
<body>
===(snip)===