Page titles in backend - <head><title>{controller} - {app.name}


#1

The page title is always “Cockpit” or app.name and it’s hardcoded in app.php. With multiple tabs open, I have to search the right one again and again. If it were something like CollectionName - Edit | app.name or Accounts - Settings | app.name, it would be much more clearly.

I digged into the code, but I didn’t find a very useful way to detect the current page. It would be possible, to split $app['route'] or the called controller into a meaningful page title, but I’m not sure, if this would catch all possible scenarios.

A builtin mechanism to detect the current page name could also be reused to create breadcrumbs automatically. Right now, they are hardcoded in the module views, too.


#2

Thanks for the suggestion! I’ll add it o my todo list


#3

For others, who don’t want to wait for the feature, I wrote a workaround. Add this to /config/bootstrap.php:


// change page titles
$app->on('app.layout.contentbefore', function(){
    
    $route = explode('/', substr($this['route'],1));
    
    if (isset($route[1]) && $route[1] == 'entry')
        $route[3] = 'Edit';
    
    $title = '';
    for (end($route); key($route)!==null; prev($route)){
        $title .= !empty(current($route)) ? $this->helpers['i18n']->get(ucfirst(current($route))) . ' - ' : '';
    }
    
    $title .= $this['app.name'];
    echo "<script>document.title = '$title'</script>";
    
});


#4

Added generic title generation wit this commit: https://github.com/agentejo/cockpit/commit/1c7bbdc43c12a241450b380907057dffbdf748b2