Log in with virtual page

I’m following the Restricting access coockbook but I would like the page to be a virtual one. I converted the .txt files (It’s multi-language site) to a virtual page following the example of simple virtual page guide for multilingual site and deleted the page from the content folder

The page shows up but when I login it sends me to the error page. I did not modified any other files.

It works if I comment out the routes and use the txt files on the content folder. Here are the txt files and the virtual page:


Title: Iniciar sesión


Alert: Correo o contraseña inválidos.


Email: Correo electrónico


Password: Contraseña


Button: Iniciar sesión


Title: Login


Alert: Invalid user or password


Email: Email


Password: Password


Button: Log in

my config.php


return [
    'debug' => true,
    'languages' => true,
    'date.handler'  => 'strftime',
    'languages.detect' => true,
    'routes' => [
            'pattern' => '(es|en)/login',
            'action' => function ($lang) {

                $data = [
                    'slug' => 'login',
                    'template' => 'login',
                    'translations' => [
                        'es' => [
                            'code' => 'es',
                            'content' => [
                                'title' => 'Iniciar sesión',
                                'alert' => 'Correo o contraseña no válidos.',
                                'email' => 'Correo electrónico',
                                'password' => 'Contraseña',
                                'button' => 'Iniciar sesion'
                        'en' => [
                            'code' => 'en',
                            'content' => [
                                'title' => 'Login',
                                'alert' => 'Invalid user or password.',
                                'email' => 'Email',
                                'password' => 'Password',
                                'button' => 'Log in'

                $page = Page::factory($data);

                site()->visit($page, $lang);

                return $page;
            'pattern' => '(es|en)/logout',
            'action'  => function() {

            if ($user = kirby()->user()) {

            go(kirby()->languageCode() . '/login');


What’s the point of doing it like this?

So the page won’t show up on the list of pages and test what can be done with kirby :stuck_out_tongue: If it’s not possible it’s ok!

But the reason why this is happening is not that it doesn’t work, but that your route only listens to a GET request. Add

'method' => 'GET|POST',

to your route and you should be good to go.

1 Like

It works, thanks!