The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
allow page-specific external CSS - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Modifications and Hackery (https://userspice.com/forums/forumdisplay.php?fid=29) +--- Thread: allow page-specific external CSS (/showthread.php?tid=206) |
allow page-specific external CSS - plb - 08-18-2016 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)=== allow page-specific external CSS - mudmin - 08-18-2016 I love that idea! That's great! |