Adjust layout for edit mode

Submitted by herent - 3 years ago

Often theme layouts break when you enter edit mode. If you put a class on the body tag to let your code know if you're editing (or can view the edit bar) then you can make micro-adjustments to your layout or block template's css to keep it from looking *too* weird.

<?php 
$c = Page::getCurrentPage();
$p = new Permissions($c);
if ($p->canViewToolbar()) {
    $canWrite = "can-write";
} else {
    $canWrite = "no-write";
}
$isEditMode = $c->isEditMode();
if ($isEditMode) {
    $editActive = " edit-active";
} else {
    $editActive = " edit-inactive";
}
?>
<body class="<?php echo $canWrite . $editActive; ?>">
Stats Categories Tags
comments powered by Disqus