Closed HonkXL closed 3 years ago
I would love to implement this feature but I really can't figure out how to detect the current page we're on. This was easy in webtrees 1 but I can't figure out how to do this in webtrees 2. Maybe @fisharebest can help us.
Look at HitCountFooterModule
, which also needs to detect the current page ("route").
e.g.
$route = $request->getAttribute('route');
if ($route->name === TreePage::class) {
/* on the home page */
}`
Thanks for your response. I've tried this but the problem is that I don't know where to put this code in my script. I tried it at the top of the FancyImagebar function starting with
$request = app(ServerRequestInterface::class);
And then your code. But var_dump($route) gives an empty array. Any idea how I can solve this?
I just cloned your latest code from github.
This works for me:
/**
* Generate the html for the Fancy imagebar
*/
public function fancyImagebar(): string
{
$request = app(ServerRequestInterface::class);
$tree = $request->getAttribute('tree');
// Get the current route
$route = $request->getAttribute('route');
var_dump($route->name);exit;
I see Fisharebest\Webtrees\Http\RequestHandlers\TreePage
(or whatever page I am viewing)
Thanks Greg for your help. It works.
In fancy imagebar for webtrees 1.x it was possible to show it on the start page only. Would be great to have this feature in the latest version, too.