Simple Machines Community Forum

Customizing SMF => Graphics and Templates => Topic started by: mabley on February 05, 2018, 01:37:21 PM

Title: Theme Variant per Board
Post by: mabley on February 05, 2018, 01:37:21 PM
I'm using SMF 2.0.15 and building a theme with color variants.

Right now, it's possible to set a theme per board, but I can't seem to set a variant per board. Does anyone know how to do this?
Title: Re: Theme Variant per Board
Post by: Aleksi "Lex" Kilpinen on February 11, 2018, 03:56:25 AM
I don't think that's easily possible without you making a separate theme out of the variants you want to use like that.
Title: Re: Theme Variant per Board
Post by: Antechinus on February 19, 2018, 03:51:40 AM
Interesting question. My gut (which admittedly is out of practice on this stuff) is telling me it should be possible. A bit convoluted, but possible. Basically, all you want to do is call CSS by board, for which you in essence just need a CSS file name and a board ID.

All the standard variant system does is set a general call for a variant CSS file in the head section of index.template.php, along with calls for some variant versions of icons in some templates where applicable. So, rejigging that to call a CSS file by board ID or by action should do the trick. I very vaguely remember some such trickery in something I worked on, but offhand I can't remember exactly what it was.

To cut through the BS: yes, it should be possible.

The next question is: why do you want to do it?
Title: Re: Theme Variant per Board
Post by: drewactual on February 20, 2018, 12:26:56 PM
it doesn't get a whole lot easier than this.   this is a variant of something i picked up here some time back, but can't recall where/who from.  All i did was intro the php include and external file, as well as multiple's by using the elseif operator.

you can use this however you see fit- and it works cleanly in many ways to include full out 'board sensitive' css or simple images... I use it to present a different header image for a board... simply use a php include to a new file you're about to create... in that file:



<?php
if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '1' ) || ( isset($board) && $board == '1' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '2' ) || ( isset($board) && $board == '2' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '3' ) || ( isset($board) && $board == '3' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '4' ) || ( isset($board) && $board == '4' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '5' ) || ( isset($board) && $board == '5' )) {
  echo 
'{whatever you want to inject}'; }
  
 else {
  echo 
'{whatever your base is}'; }
?>




the area {whatever you want to inject} is where your changes are offered.  you can use css, html, or even another php include if you want (such as you may if you're 'injecting' a large amount of info such as a big css or a big js)...

the area {whatever your base is} is what you want to appear (inject) on a 'standard' page- or left blank between the ' ' to not do anything.... it's there though, if you need it. 

the board numbers you should match up with the boards you intend to use this on.... i just numbered them 1, 2, 3, 4, and 5...

the function is injected on either your index.template, boardindex.template, or message.index template (adjusting accordingly) by a simple php include- such as:
include('url to the file you just made');

it's nice that it's an 'include' as it won't break anything if it doesn't work- such as jacked up code (if it's js or php you're 'injecting' that has a syntax error).  if it was 'require' (which you can use, but i wouldn't rec it) it would break the render if it tripped over itself.

at any rate, this is a useful little script to do (if i understand correctly) what you want to accomplish.  I hope you find purpose for it!

Title: Re: Theme Variant per Board
Post by: mabley on February 28, 2018, 06:18:34 PM
Thank you so much, everyone! Thanks for taking the time to look at my question and offer some information. I'll look into this.