News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Theme Colors - Change on a board level

Started by James Gryphon, May 13, 2016, 06:46:35 PM

Previous topic - Next topic

James Gryphon

I've been trying to implement Ante's body tagging to work on Core, without any luck. Since I obviously don't have any clue what I'm doing I thought I'd save myself a few more hours beating my head against the wall and ask about it here.

I made these modifications to index.template.php, replacing this:
</style>';
// YSHOUT END - <head> code

// We'll have to use the cookie to remember the header...
if ($context['user']['is_guest'])
{
$options['collapse_header'] = !empty($_COOKIE['upshrink']);
$options['collapse_header_ic'] = !empty($_COOKIE['upshrinkIC']);
}

// Output any remaining HTML headers. (from mods, maybe?)
echo $context['html_headers'];

echo '
</head>
<body>';

with this:
   </style>';
   // YSHOUT END - <head> code

   // We'll have to use the cookie to remember the header...
   if ($context['user']['is_guest'])
   {
      $options['collapse_header'] = !empty($_COOKIE['upshrink']);
      $options['collapse_header_ic'] = !empty($_COOKIE['upshrinkIC']);
   }

   // Output any remaining HTML headers. (from mods, maybe?)
   echo $context['html_headers'];

   // Allow setting body tag id by action or board.
   $body_id = array();
   if (!empty($context['current_board']))
      $body_id[] = 'board_'. $context['current_board'];
   if (empty($body_id))
      $body_id[] = 'action_index';
   echo '
</head>
<body id="', implode(' ',$body_id), '">';


This didn't seem to obviously break anything. Implementing changes in the CSS file using the board tags doesn't have any apparent effect, though. It just changes the color of everything on the forum.

a:link, a:visited
{
   color: #990000;
   background-color: transparent;
   text-decoration: none;
}

#board_16 a:link, a:visited
{
   color: #000000;
   background-color: transparent;
   text-decoration: none;
}
This results in most links (oddly, not all of them) being black everywhere.

What've I messed up this time?

Irisado

Please avoid posting in old topics which are a year old, especially when they have been marked as solved, in the future.  I've split your post to create a new topic.
Soñando con una playa donde brilla el sol, un arco iris ilumina el cielo, y el mar espejea iridescentemente

Antechinus

"This results in most links (oddly, not all of them) being black everywhere."

If you mean when you are inside board #16 then yes, that's what it would do. Exactly what do you want it to do?

qc

Does that work for you?
#board_16 a:link, #board_16 a:visited
{
   color: #000000 !important;
   background-color: transparent !important;
   text-decoration: none !important;
}
Playing quizduell? Having quizduell questions? Our german quizduell forum quizcommunity.de is looking for quiz freaks to come and play quizduell with us :)

James Gryphon

Quote from: Antechinus on May 15, 2016, 05:07:12 PM
"This results in most links (oddly, not all of them) being black everywhere."

If you mean when you are inside board #16 then yes, that's what it would do.
Well, I meant everywhere on the forum, not just in that single board. As it turned out, though, I did manage to fix that (and other problems) One error in thinking I ran into: I thought of the new #board_13 prefixed code as being derived somehow from the old code, meaning that it would inherit attributes I didn't change. I learned (after a longer time than it probably should have taken) that's not how it works.

Now I've started working on trying to expand this system to allow me to use the same settings for multiple boards. Here's the code I managed to hack into existence (replacing the original code in index.template.php from the first post):

      // Allow setting body tag id by action or board.
   $body_id = array();
if (!empty($context['current_board'])) {
if ($context['current_board'] == 15)
      $body_id[] = 'board_2';
else $body_id[] = 'board_'. $context['current_board']; }

   if (empty($body_id))
      $body_id[] = 'action_index';
   echo '
</head>
<body id="', implode(' ',$body_id), '">';


As you can see, this code checks for the board being displayed, and if it's 'supposed' to, forcibly changes its ID to match the requirements to set its theme. This was the first way I could think of to serve the function of creating a greater multi-board group that share the same theme characteristics.

Surely there's got to be something I'm missing here; it seems too easy and kludgy for me to believe this is the best way to do this.

qc

Why is your body_id an array? Also, better use the class attribute if you wish to assign one set of CSS rules to multiple boards. This would also allow you to extend or modify a general set of rules for specific boards.

If you wish to specify the same CSS rules for multiple IDs, you could just repeat the selectors (#board_15 a, #board_2 a { ... }). Use a CSS preprocessor to make the job easier (e. g. less: #board_15, #board_2 { a { ... } } or using &:extend(.my-board))
Playing quizduell? Having quizduell questions? Our german quizduell forum quizcommunity.de is looking for quiz freaks to come and play quizduell with us :)

Antechinus

@qc: it was in an array because the code I ripped had extra options for body class, and I was being lazy when I ripped it. The original looked like this:

// Allow setting body tag class by action or board.
$body_class = array();
if (!empty($context['current_action']))
$body_class[] = 'action_'. $context['current_action'];
if (!empty($context['current_board']))
$body_class[] = 'board_'. $context['current_board'];
if (!empty($context['current_topic']))
$body_class[] = 'topic_'. $context['current_topic'];
if (empty($body_class))
$body_class[] = 'action_index';

echo '
</head>
<body';


I just changed the minimum for him, and used it to set an id. But sure, you could do the PHP other ways. I suppose the cleanest would be:

<body ',!empty($context['current_board'])?'id="board_'. $context['current_board']"':'', '>

Then just use whatever selectors to do the relevant CSS, as you said, if wanting the same changes on multiple boards.

Advertisement: