Loading an alternate CSS file for some boards

Started by @rjen, February 17, 2019, 02:32:36 PM

Previous topic - Next topic

@rjen

On my 2.0.15 forum I have a number of boards that are only accessible to certain member groups.

To make it very clear to these members that they are in the special boards I have applied a simple fix to load an alternative .css file for these boards. Solution used in 2.0.15 from here: https://www.simplemachines.org/community/index.php?topic=533617

I do not want to apply a completely different theme to these boards...

My old code:

// nodig om een ander Stylesheet te kiezen per board
$club = array('44','5','6','45','9','64','60','62','53','72','61','54','7','55','10','56','36','13','11','12','27','29','30','14','15','16','17','73');

if(!empty($GLOBALS['board']) &&  in_array($GLOBALS['board'], $club))
{
echo'<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'],'_club.css?fin20" />';
}
else
{
echo'<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?fin20" />';
}


Looking to do the same in 2.1 RC1 but it needs a different approach it seems: either using  template_css(); function of maybe use a similar code in index.template.php.

My old code does not work: it seems that the $settings['theme_url'] is now $context['smf_theme_url'], but it still does not work to make the switch.

Can anyone help how to apply this trick in SMF 2.1?
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

Gwenwyfar

Use the #board_N ID on the container of each board section. There is a class on the html body as well, if you need it inside a board.
"It is impossible to communicate with one that does not wish to communicate"

@rjen

Thanks for the hint, but thats a bit too cryptic for me... use the board_n ID how?
I am proficient in reading and manipulating existing code, but building from scratch is above my skill level.
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

SychO

you can load css files before the call to template_css() function, however I recommend you use the loadCSSFile() function to enable file minimization and possibly other custom settings

the code would be like this

// nodig om een ander Stylesheet te kiezen per board
$club = array('44','5','6','45','9','64','60','62','53','72','61','54','7','55','10','56','36','13','11','12','27','29','30','14','15','16','17','73');

if(!empty($GLOBALS['board']) &&  in_array($GLOBALS['board'], $club))
{
$settings['disable_files'][] = 'smf_index';
loadCSSFile('index_club.css', array('minimize' => true));
}


I haven't tested the code but it should work, just make sure you use it before template_css()

a list of parameters from Load.php

* @param string $fileName The name of the file to load
* @param array $params An array of parameters
* Keys are the following:
* - ['external'] (true/false): define if the file is a externally located file. Needs to be set to true if you are loading an external file
* - ['default_theme'] (true/false): force use of default theme url
* - ['force_current'] (true/false): if this is false, we will attempt to load the file from the default theme if not found in the current theme
*  - ['validate'] (true/false): if true script will validate the local file exists
*  - ['rtl'] (string): additional file to load in RTL mode
*  - ['seed'] (true/false/string): if true or null, use cache stale, false do not, or used a supplied string
*  - ['minimize'] boolean to add your file to the main minimized file. Useful when you have a file thats loaded everywhere and for everyone.
*  - ['order_pos'] int define the load order, when not define it's loaded in the middle, before index.css = -500, after index.css = 500, middle = 3000, end (i.e. after responsive.css) = 10000
* @param string $id An ID to stick on the end of the filename for caching purposes
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

SychO

oh & you'd also have to add $settings to the globals
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

@rjen

Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

Gwenwyfar

Quote from: @rjen on February 17, 2019, 02:48:54 PM
Thanks for the hint, but thats a bit too cryptic for me... use the board_n ID how?
I am proficient in reading and manipulating existing code, but building from scratch is above my skill level.

It's to use in the css. The boards are already named in 2.1
"It is impossible to communicate with one that does not wish to communicate"

@rjen

Quote from: Gwenwyfar on February 17, 2019, 03:25:31 PM
Quote from: @rjen on February 17, 2019, 02:48:54 PM
Thanks for the hint, but thats a bit too cryptic for me... use the board_n ID how?
I am proficient in reading and manipulating existing code, but building from scratch is above my skill level.

It's to use in the css. The boards are already named in 2.1

I did not get that from your first post. Interesting option though: will check that out too...
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

@rjen

Checked it out. The board ID's may be useful to control board icons on the board index, but what I have with the css-switch is actually a bit more suitable for what I need.

But thanks for the tip
Running SMF 2.1 with latest TinyPortal at www.fjr-club.nl

Advertisement: