Skip to content

Commit

Permalink
Display: Add feature to add CSS class to HTML main <section> element …
Browse files Browse the repository at this point in the history
…for specific enabled features that are used more globally through global variable $htmlContentExtraClass - refs BT#13334
  • Loading branch information
ywarnier committed Aug 23, 2022
1 parent efb8c1d commit cd63f7e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
25 changes: 25 additions & 0 deletions main/inc/lib/template.lib.php
Expand Up @@ -223,6 +223,10 @@ public function __construct(
$this->set_footer($show_footer);
$this->set_header($show_header);

// Extra class for the main cm-content div
global $htmlContentExtraClass;
$this->setExtraContentClass($htmlContentExtraClass);

$this->set_header_parameters($sendHeaders);
$this->set_footer_parameters();

Expand Down Expand Up @@ -462,6 +466,27 @@ public function set_header($status)
$this->assign('show_course_shortcut', $courseToolBar);
$this->assign('show_course_navigation_menu', $show_course_navigation_menu);
}
/**
* Sets an extra class for the main cm-content div.
* To use, give a new row to $htmlContentExtraClass like so: `$htmlContentExtraClass[] = 'feature-item-user-skill-on';`
* before any Display::display_header() call.
*/
public function setExtraContentClass($htmlContentExtraClass): void
{
if (empty($htmlContentExtraClass)) {
$extraClass = '';
} else {
if (is_array($htmlContentExtraClass)) {
$extraClass = implode(' ', $htmlContentExtraClass);
} else {
$extraClass = $htmlContentExtraClass;
}
$extraClass = Security::remove_XSS($extraClass);
$extraClass = trim($extraClass);
$extraClass = ' class="'.$extraClass.'"';
}
$this->assign('html_content_extra_class', $extraClass);
}

/**
* Returns the sub-folder and filename for the given tpl file.
Expand Down
4 changes: 3 additions & 1 deletion main/template/default/gradebook/skill_rel_user.tpl
@@ -1,3 +1,4 @@
<div {{ html_content_extra_class }}>
<h3>{{ user.complete_name_with_username }}</h3>
<br />
<script>
Expand Down Expand Up @@ -64,4 +65,5 @@
</td>
</tr>
{% endfor %}
</table>
</table>
</div>
2 changes: 1 addition & 1 deletion main/template/default/layout/page.tpl
Expand Up @@ -45,7 +45,7 @@
{% endif %}

<!-- START CONTENT -->
<section id="cm-content">
<section id="cm-content"{{ html_content_extra_class }}>
<div class="container">
{% if show_course_shortcut is not null %}
<!-- TOOLS SHOW COURSE -->
Expand Down
2 changes: 1 addition & 1 deletion main/template/default/layout/show_header.tpl
Expand Up @@ -45,7 +45,7 @@
{% endif %}

<!-- START CONTENT -->
<section id="cm-content">
<section id="cm-content"{{ html_content_extra_class }}>
<div class="container">
{% if show_header == true %}
{% if show_course_shortcut is not null %}
Expand Down

0 comments on commit cd63f7e

Please sign in to comment.