fisharebest / webtrees

Online genealogy
https://webtrees.net
GNU General Public License v3.0
488 stars 301 forks source link

How to get tree URL? #2888

Closed jchue closed 4 years ago

jchue commented 4 years ago

Forgive me if this is the wrong place to ask. I'm still familiarizing myself with the codebase- is there a straightforward way to obtain the URL for a tree's homepage? I tried using the route() function in Helpers/functions.php, but it's just giving me the base URL + /index.php?route=/tree/tree/{tree} (with the curly braces instead of the actual tree name).

fisharebest commented 4 years ago

You need to provide all the route parameters as a second argument.

route($route_name, [$param1 => $value1, $param2 => $value2, ...]

Any extra parameters that are not place-holders will be added to the URL as a query parameter.

e.g.

route('tree-page', ['tree' => $tree->name()]);

Note that there are two styles of route name.

The former are gradually being replaced by the latter.

You can see them all in app/Http/Routes/WebRoutes.php.

fisharebest commented 4 years ago

Just to clarify my last point, the current code:

route('tree-page', ['tree' => $tree->name()]);

will shortly be changing to something like

route(TreePage::class, ['tree' => $tree->name()]);

jchue commented 4 years ago

Thank you! Does this mean that, in your example after the code has changed, I would need to import the TreePage request handler (in addition to the route helper) to be able to do this in a theme module?

fisharebest commented 4 years ago

I would need to import the TreePage request handler

You'd need to have a line like this at the top of your script

use Fisharebest\Webtrees\Http\RequestHandlers\TreePage;

fisharebest commented 4 years ago

BTW - that particular change will be happening later today...

jchue commented 4 years ago

Got it. Thanks!