# Language switch virtual page error

**URL:** https://forum.getkirby.com/t/language-switch-virtual-page-error/32336
**Category:** Questions
**Tags:** v4
**Created:** [August 27, 2024, 3:21pm UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336 "2024-08-27T15:21:43Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![kmajort](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kmajort/32/11181_2.png) [@kmajort](https://forum.getkirby.com/u/kmajort)
#### Post date: [August 27, 2024, 3:21pm UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336/1 "2024-08-27T15:21:43Z")

</div>

1 kirby page in 2 languages (kirby 4.3, php 8.3)  
nl/enquetes/enquete-nl  
fr/enquetes/enquete-fr  
nl is default language  
I have a virtual ‘end’ page.

nl/enquetes/enquete-nl/end → works  
but when i switch to ‘fr’ i got and error (page-\>parent() is NULL in virtual page ‘endtemplate’. In kirby3 this worked i think.

config-file:

```auto
'routes' =>[  
  [
    'pattern' =>'(nl|fr)/enquetes/(:any)/end',
    'action' => function($lang,$enquete){      
      $data = [
        'slug' => 'end',
       
        'parent' => page('enquetes/'.$enquete),
        'template' => 'endtemplate', 
        'content' => [
          'title' => 'Thanks for your participation'            
        ]
      ];
      $page = Page::factory($data);
      site()->visit($page, $lang);
      return $page;
    
    }
  ],

```

---

<div class="post-metadata">

### Author: ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)
#### Post date: [August 27, 2024, 4:19pm UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336/2 "2024-08-27T16:19:59Z")

</div>

Hm, I cannot reproduce this when I test a similar setup it in a Starterkit.

---

<div class="post-metadata">

### Author: ![kmajort](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kmajort/32/11181_2.png) [@kmajort](https://forum.getkirby.com/u/kmajort)
#### Post date: [August 27, 2024, 6:56pm UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336/3 "2024-08-27T18:56:55Z")

</div>

Strange indeed, the error occurs here when the slug of the nl, fr page is different.  
When i test with:  
nl/enquetes/enquete and fr/enquetes/enquete  
then there is no error.  
Is it not possible to work with different slugs in this type of case (virtual multilanguage page)?  
thanks!

---

<div class="post-metadata">

### Author: ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)
#### Post date: [August 27, 2024, 7:03pm UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336/4 "2024-08-27T19:03:45Z")

</div>

Please change the route to:

```auto
	    [
		    'pattern' =>'enquetes/(:any)/end',
		    'language' => '*',
		    'action' => function($lang, $enquete){
			    $data = [
				    'slug' => 'end',
				
				    'parent' => page('enquetes/' . $enquete),
				    'template' => 'endtemplate',
				    'content' => [
					    'title' => 'Thanks for your participation'
				    ]
			    ];
			    $page = Page::factory($data);
			    site()->visit($page, $lang);
			    return $page;
			
		    }
	    ],

```

---

<div class="post-metadata">

### Author: ![kmajort](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kmajort/32/11181_2.png) [@kmajort](https://forum.getkirby.com/u/kmajort)
#### Post date: [August 27, 2024, 7:26pm UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336/5 "2024-08-27T19:26:45Z")

</div>

this goes to the error page. Is the $lang variable correct in this situation?

---

<div class="post-metadata">

### Author: ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)
#### Post date: [August 27, 2024, 8:20pm UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336/6 "2024-08-27T20:20:12Z")

</div>

Let’s verify I got it right. You want the following urls to work (I’m using en as default, de as secondary language:

1. `https://mydomain.test/en/enquetes/subpage-1/end`
2. `https://mydomain.test/en/enquetes/unterseite-1/end`

Where `unterseite-1` is set as slug in the content file of the secondary language. Is that correct?

---

<div class="post-metadata">

### Author: ![kmajort](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kmajort/32/11181_2.png) [@kmajort](https://forum.getkirby.com/u/kmajort)
#### Post date: [August 28, 2024, 6:06am UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336/7 "2024-08-28T06:06:28Z")

</div>

that’s correct and i want to use $page-\>parent()-\>title() in the end template.  
I guess there is a typo in your second url (en instead of de)  
[https://mydomain.test/de/enquetes/unterseite-1/end](https://mydomain.test/de/enquetes/unterseite-1/end)

---

<div class="post-metadata">

### Author: ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)
#### Post date: [August 28, 2024, 7:38am UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336/8 "2024-08-28T07:38:39Z")

</div>

if all pages in the tree have a slug in the secondary language, you need to adapt the route

```auto
   [
		    'pattern' =>'(enquetes|translated-slug)/(:any)/end',
		    'language' => '*',
		    'action' => function($lang, $p, $enquete){
			    $data = [
				    'slug' => 'end',
				
				    'parent' => page($p . '/' . $enquete),
				    'template' => 'endtemplate',
				    'content' => [
					    'title' => 'Thanks for your participation'
				    ]
			    ];
			    $page = Page::factory($data);
			    site()->visit($page, $lang);
			    return $page;
			
		    }
	    ],

```

Replace translated slug with the correct slug name

---

<div class="post-metadata">

### Author: ![kmajort](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kmajort/32/11181_2.png) [@kmajort](https://forum.getkirby.com/u/kmajort)
#### Post date: [August 29, 2024, 8:18am UTC](https://forum.getkirby.com/t/language-switch-virtual-page-error/32336/9 "2024-08-29T08:18:47Z")

</div>

great!! it works!!  
Thanks a lot
