Closed cweiske closed 1 year ago
Related: #584 "Use tag & lists name for HTML title"
Possible solution:
In resources/views/partials/header.blade.php
, change the line containing <title>
to:
<title>@if(isset($pageTitle)){{$pageTitle}} - @endif{{ systemsettings('system_page_title') ?: config('app.name', 'LinkAce') }}</title>
The separator is chosen as a hyphen, but maybe that should be something else (em dash, pipe) or be configurable. I first made it part of the page title system setting, but then any pages without title (e.g. the homepage) would have the separator prepended as well. That's okay if pages always have titles, though.
The contents of $pageTitle
are printed with HTML encoding, so this is not an XSS vector.
Now, the page title can be chosen by the controller, e.g. app/Providers/FortifyServiceProvider.php
:
Fortify::loginView(function () {
return view('auth.login', [
'pageTitle' => 'Login',
]);
});
As another example, here's what I used for tags (app/Http/Controllers/Models/TagController.php
):
...
return view('models.tags.index', [
'pageTitle' => 'Tags',
'tags' => $tags,
...
public function create(): View
{
return view('models.tags.create', [
'pageTitle' => 'Add tag',
]);
}
...
return view('models.tags.show', [
'pageTitle' => $tag->name,
'tag' => $tag,
...
public function edit(Tag $tag): View
{
return view('models.tags.edit', [
'pageTitle' => 'Edit tag: ' . $tag->name,
'tag' => $tag,
]);
}
This is how it comes out in my browser:
To support translations, it looks like the solution is to add the translation entry and call trans()
in the controller for strings such as 'Edit tag:' and 'Add tag'. (I neglected that extra step for my local version.)
Another solution uses views instead of passing it from the controller. I should first have looked up what the standard Laravel way of doing this is instead of just starting with the first idea that came to mind, to be honest. I'd probably have gone for the view-based option.
@Kovah let me know if you would like this as a pull request anyway (with translations support).
Looks good to me.
By the way @isset($pageTitle){{$pageTitle}} - @endisset
should also work.
Bug Description
My browser history is useless now because all pages in LinkAce have the title "LinkAce".
How to reproduce
Expected behavior
Each page should have a sensible page title.
Logs
No response
Screenshots
No response
LinkAce version
v1.12.2
Setup Method
PHP
Operating System
Linux (Ubuntu, CentOS,...)
Client details
No response