Problem with correct url - multilanguage


#1

Hallo,
i can’t get correct url in my multilanguage page.

I have two languages
In my blueprint i have this field:

link:
label: Link to page
type: select 
options: pages

In themplate i have this:
<?= $page->link() ?>

I select pages in editor for default and second language, there name of url is correct
but when second language is active on page i have still url from default language


#2

Try

<?= $pages->find($page->link())->url($site->language()->code()); ?>

#3

Thank You for attention
I haved to change type to structure, so now i have some like this:

<?php foreach($page->blocks()->toStructure() as $position): ?>
<a href="<?= $position->find($position->link())->url($site->language()->code()); ?>">link</a>
<?php endforeach ?>

but it doesn’t work
now i have page url with correct lang but without url selected page


#4

Please use $pages instead of $position first:

<?php foreach($page->blocks()->toStructure() as $position): ?>
<a href="<?= $pages->find($position->link())->url($site->language()->code()); ?>">link</a>
<?php endforeach ?>

What do you mean exactly with “url selected page”?


#6

I want to have url like this in default language:
http://localhost.eu/privacy-policy

In second language i want to have this:
http://localhost.eu/de/datenschutzrichtlinie

Its the same page with changed name for specific langauge

but now i have this debug error:
Call to a member function url() on boolean


#7

Can you paste the output from

var_dump($position->link());

from inside the foreach, and

var_dump($pages->find("privacy-policy")->url("de"));

please?