Multilang page restrict structur field

That might well be, but for $page->content('en') etc. to work, you need to define the translations.

Example (shortened):


<?php

class MembersPage extends Page
{
  public function children()
  {
    $usersPages = [];
    $users      = kirby()->users();
    foreach ($users as $key => $user) {
        $content = [
            'title'   => $user->username(),
            'role'    => $user->role(),
        ];
        $contentEn = [
            'about'    => $user->content('en')->about(),
            'dates'  => $user->content('en')->dates()->yaml(),
        ];
        $contentDe = [
            'about'    => $user->content('de')->about(),
            'dates'  => $user->content('de')->dates()->yaml(),
        ];

      $userPages[] = [
        'slug'     => Str::slug($user->username()),
        'num'      => $user->indexOf($users),
        'template' => 'member',
        'model'    => 'member',
        'content'  => array_merge($content, $contentEn),
        'translations' => [
            'de' => [
                'code' => 'de',
                'content' => array_merge($content, $contentDe),
            ],
            'en' => [
                'code' => 'en',
                'content' => array_merge($content, $contentEn),
            ],
        ]
      ];
    }
    return Pages::factory($userPages, $this);

  }

}

Do I understand correctly you merge the complete content ? but I only want to merge dates().

Could I also just merge the dates() field of all languages, or does that not work because there is a conflict when changing the language?

   <?php

class MembersPage extends Page
{
  public function children()
  {
    $userPages;
    $users      = kirby()->users();
    foreach ($users as $key => $user) {

      $content_de = [
        'language' => $user->language(),
        'title'    => $user->username(),
        'role'  => $user->role(),
        'type'    => $user->member_type()->value(),
        'street'    => $user->street(),
        'city'    => $user->city(),
        'zip'    => $user->zip(),
        'website'    => $user->website(),
        'about'    => $user->about(),
        'userid'    => $user->id(),
        'cover'    => $user->cover()->yaml(),
        'canton'    => $user->canton(),
        'dates'  => $user->content('de')->dates()->yaml(),
      ];
      $content_fr = [
        'language' => $user->language(),
        'title'    => $user->username(),
        'role'  => $user->role(),
        'type'    => $user->member_type()->value(),
        'street'    => $user->street(),
        'city'    => $user->city(),
        'zip'    => $user->zip(),
        'website'    => $user->website(),
        'about'    => $user->about(),
        'userid'    => $user->id(),
        'cover'    => $user->cover()->yaml(),
        'canton'    => $user->canton(),
        'dates'  => $user->content('fr')->dates()->yaml(),
      ];
      $content_it = [
        'language' => $user->language(),
        'title'    => $user->username(),
        'role'  => $user->role(),
        'type'    => $user->member_type()->value(),
        'street'    => $user->street(),
        'city'    => $user->city(),
        'zip'    => $user->zip(),
        'website'    => $user->website(),
        'about'    => $user->about(),
        'userid'    => $user->id(),
        'cover'    => $user->cover()->yaml(),
        'canton'    => $user->canton(),
        'dates'  => $user->content('it')->dates()->yaml(),
      ];



      $userPages[] = [
        'slug'     => Str::slug($user->username()),
        'num'      => $user->indexOf($users),
        'template' => 'member',
        'model'    => 'member',
        'content'  => array_merge($content_de, $content_fr, $content_it),
        'translations' => [
          'fr' => [
            'code' => 'fr',
            'content' => array_merge($content_de, $content_fr, $content_it),
          ],
          'it' => [
            'code' => 'it',
            'content' => array_merge($content_de, $content_it, $content_it),
          ],
        ]


      ];
    }
    return Pages::factory($userPages, $this);
  }
}

In the example above, I’m only merging the $content array (which is the same for all languages) with the language specific content for each language in the model, so that you get a translation with all content for each language.

Yes, you could do the merging for the dates field here already if you want, or do that in your template.

isn’t the value overwritten with the same key with array merge?

<?php

class MembersPage extends Page
{
  public function children()
  {
    $userPages;
    $users      = kirby()->users();
    foreach ($users as $key => $user) {

      $content_de = [
        'language' => $user->language(),
        'title'    => $user->username(),
        'role'  => $user->role(),
        'type'    => $user->member_type()->value(),
        'street'    => $user->street(),
        'city'    => $user->city(),
        'zip'    => $user->zip(),
        'website'    => $user->website(),
        'about'    => $user->about(),
        'userid'    => $user->id(),
        'cover'    => $user->cover()->yaml(),
        'canton'    => $user->canton(),
        'dates'  => $user->content('de')->dates()->yaml(),
      ];
      $content_fr = [
        'dates'  => $user->content('fr')->dates()->yaml(),
      ];
      $content_it = [
        'dates'  => $user->content('it')->dates()->yaml(),
      ];



      $userPages[] = [
        'slug'     => Str::slug($user->username()),
        'num'      => $user->indexOf($users),
        'template' => 'member',
        'model'    => 'member',
        'content'  => array_merge($content_de, $content_it),
        'translations' => [
          'fr' => [
            'code' => 'fr',
            'content' => array_merge($content_de, $content_fr),
          ],
          'it' => [
            'code' => 'it',
            'content' => array_merge($content_de, $content_it),
          ],
        ]


      ];
    }
    return Pages::factory($userPages, $this);
  }
}

Yes, in the end it doesn’t matter but it’s kind of superfluous.

holy,holy — okay now i get!

thank you @texnixe for your patient help.

template

	foreach ($kirby->languages() as $language) :
		foreach ($article->content($language->code())->dates()->toStructure() as $dates) :


			array_push($events, [
				"username" => $article->title(),
				"date" => strtotime($dates->date()),
				"title" => $dates->title(),
				"location" => $dates->location(),
				"city" => $dates->city(),
				"website" => $dates->website(),
				"festival" => $dates->festival(),
				"canton" => $dates->canton()
			]);

		endforeach;
	endforeach;

model


  foreach ($users as $key => $user) {

      $content_de = [
        'language' => $user->language(),
        'title'    => $user->username(),
        'role'  => $user->role(),
        'type'    => $user->member_type()->value(),
        'street'    => $user->street(),
        'city'    => $user->city(),
        'zip'    => $user->zip(),
        'website'    => $user->website(),
        'about'    => $user->about(),
        'userid'    => $user->id(),
        'cover'    => $user->cover()->yaml(),
        'canton'    => $user->canton(),
        'dates'  => $user->dates()->yaml(),
      ];
      $content_fr = [
        'dates'  => $user->content('fr')->get("dates")->yaml(),
      ];
      $content_it = [
        'dates'  => $user->content('it')->get("dates")->yaml(),
      ];



      $userPages[] = [
        'slug'     => Str::slug($user->username()),
        'num'      => $user->indexOf($users),
        'template' => 'member',
        'model'    => 'member',
        'content'  => $content_de,
        'translations' => [
          'de' => [
            'code' => 'de',
            'content' => $content_de,
          ],
          'fr' => [
            'code' => 'fr',
            'content' => $content_fr,
          ],
          'it' => [
            'code' => 'it',
            'content' => $content_it,
          ],
        ]


      ];
    }

to fully understand I had to use translations[ ] in the model to access languages in the template ?

You need the translations array to be able to access $content($languageCode), because this relies on the translation. See