October CMS resources and help articles

Simple and to the point. Optimized by the community.

Making the Settings screen logo clickable

1
by mohsin, last modified on April 7th, 2021

So I wanted to link the uploaded backend logo (the one that appears on /backend/system/settings) to my website.

You can do this in 2 ways. First being by overloading the controller middleware:

    Event::listen('backend.page.beforeDisplay', function ($backendController, $action, $params) {
        if ($backendController instanceof \System\Controllers\Settings && $action === 'index') {
            $backendController->middleware(function ($request, $response) {
                $basePath = url('//www.yoururl.com');
                $injectedJs = <<< THEINJECTEDJS
<script>
    $(function() {
        $('.layout-cell .oc-logo-transparent').on('click', function(){
             document.location.href = '$basePath';
             return false;
        });
    });
</script>
THEINJECTEDJS;
                $response->setContent($response->getContent() . $injectedJs);
            });
        }
    });

The second, you could also do this by listening to the extendHead view event:

    Event::listen('backend.layout.extendHead', function ($controller, $layout) {
        $basePath = url('//www.yoururl.com');
                return <<< THEINJECTEDJS
<script>
    $(function() {
        $('.layout-cell .oc-logo-transparent').on('click', function(){
             document.location.href = '$basePath';
             return false;
        });
    });
</script>
THEINJECTEDJS;
                }

Which is similar but does the same without overloading the middleware function.

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?