How to get the title from a text document of the second language


I have a multi-language site with sections (like a one-pager), built from seperate text documents. I link to each section with an anchor. The url to the anchor is built from the page url + the title of the page.

For example i have these two text documents: a) with “Title: page1_german” and b) page1_english.en.txt with “Title: page1_english”.

Now i need to link to the url+anchor of the translated site.

So far i have this code for the main.php and the section.php:

<?php snippet('header'); ?>
<?php foreach(page('main')->children()->visible() as $section): ?>
<?php snippet($section->uid(), array('data' => $section)) ?>
<!— html for each content section —>
<?php endforeach ?>

<?php foreach($site->languages() as $language): ?>
<a href="<?= $page->url($language->code()) ?>#<?php echo str::slug($data->title()) ?>"> <?= str::upper($language->code()) ?> </a>
<?php endforeach ?>

Part of it is from the ‘Switch B Example’ in the docs (

But the following will only show the title (anchor) of the current language:
<?php echo str::slug($data->title()) ?>

How can i get the title of the translated text document?


The content() method is your friend, because it accepts a language parameter: $data->content($language->code())->title().


Perfect! Thanks a lot!