Route using username

hello,

i have a link in my blueprint info field to the url ‘/overview’.
to get to the users overview i think of implementing a route like so

[
               'pattern' => '/back',
                    'action'  => function () {
                      
                              go('/'. $kirby->$user->name());
                              }
                         ],

but apparently kirby doesnt know the $kirby or $user objects:

Undefined variable $kirby

(i also thought of putting the $user->name() directly in the link, but that didnt work either.)

any help very much appreciated!

fusi

Since the $kirby variable isn’t available, you can use the kirby() helper to get the same object. So kirby()->user()->name(). Please notice that it’s not $user in this case but user(). Variables (starting with a $) will only be a starting point of such a chained command. For what you’re doing you need to call the user() method on the kirby object (which you get from the kirby helper).

awesome, tnx!
i still don’t yet understand when to use what but let that be my problem for now…

In templates and in snippets, the following variables are available by default:

  • $kirby
  • $site
  • $page
  • $pages

In all other contexts, you have to create a new object first, or use the helpers (page(), kirby(), site()).

1 Like