JustCarmen / webtrees-fancy-imagebar

Fancy Imagebar module for webtrees
http://justcarmen.nl
GNU General Public License v3.0
12 stars 6 forks source link

Feature request - show fancy imagebar only on start page #65

Closed HonkXL closed 3 years ago

HonkXL commented 3 years ago

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.

JustCarmen commented 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.

fisharebest commented 3 years ago

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 */
}`
JustCarmen commented 3 years ago

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?

fisharebest commented 3 years ago

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)

JustCarmen commented 3 years ago

Thanks Greg for your help. It works.