"go()" with params?

Hi there,

i am currently adding the possibility to lock pages for visiters who are not logged in. So if the user is logged in, he sees the page and i f not he will be sent to the login page:

{{ go("/login") }}

The question is, can i pass values in this go-statement? I want to pass page.url so that i can reffer to the url in the controller of the login form, to sent the user back to the page he wanted to see after a successfull login.

greetings

No, at least not as function parameters.

You could add the referrer page as query string to login, (login?referrer=where-i-came-from), or set a cookie.

I decided to realize it with params as you suggested.

{% set goPage = page.id %}
{{ go("/login?goThen="~goPage) }}

In my login controller i tried to get this param. But get the error “Undefined array key ‘goTo’”
I used the following simple code and dont know why this isnt working in this context:

$goTo = $_GET['goTo'];

Since you name your parameter “goThen”, you should get it by that name:

$goTo = $_GET['goThen'];

Hi thanks for your reply.
I had that correct before but forgot to rename.
But i still have the same error “Undefined array key ‘goThen’”

$goTo = $_GET['goThen']

Use get('goThen') or $goTo = $_GET['goThen'] ?? null; to prevent this error when the query param is not set.

In the long run, it pays to learn what such error messages mean and how to prevent them…