Body Classes

LiveWhale adds dynamic body classes for the top level directory each page is in, the group that owns it, and several possible states. While this is not sufficient for large-scale layout/design changes— use a theme in that case— it can be helpful for smaller variations in designs that share a large portion of their styles. Or, helping a design respond to specific content choices.

Using the following example page:

http://your.domain.edu/student-groups/comedy-shmomedy/

The body tag might look like:

<body class="plain-page images-banner_hidden body_student-groups group_comedy_shmomedy">

Here is an explanation of classes above:

plain-page
This class one is coded into the page via the template, e.g. it is hard-coded.

images-banner_hidden
This is added dynamically based on the state of the content on the page— in this case, the editable region images-banner also has a class “optional” on it and is currently empty, so LiveWhale appends a hidden state class to the body so that you can code to that state. Were the editable region not be empty, this would not be appended.

body_student-groups
This is the group directory of the group that owns the page, per group=me.

group_comedy_shmomedy
This is the group that owns the page.

Adding body classes using a custom module

LiveWhale already adds several body classes to every page dynamically at the time of output (see above). But you can add additional body classes programmatically. The method in question is:

$_LW->appendBodyClass('class_name');
// class_name is the CSS class you wish to apply

You can add the body class in any handler prior to, but not including onOutput, as the page has already been output by that point. Unless your logic requires otherwise, the recommended handlers for utilizing this method are onLoad or onBeforeOutput.

<?php

// file: client/modules/add_body_class/public.application.add_body_class.php

$_LW->REGISTERED_APPS['add_body_class']=[
  'title'=>'Add Body Class',
  'handlers'=>['onLoad'],
];

class LiveWhaleApplicationAddBodyClass {

  public function onLoad() { // runs when this application module is loaded
    global $_LW;
    // some conditional logic that dictates when to add the body class
    // such as if(strpos($_SERVER['REQUEST_URI'], '/path/to/begin/with') === 0) ...
    $_LW->appendBodyClass('my_body_class');
  }

}
?>

On this page