Hi,
I have a structure fields for countries but in my frontend I want to use the english version specifically.
I need to acces both the current language value and the english value in the same foreach loop. I need the english version as the value and the translated value to display to the user.
<?php foreach ($page->countries()->toStructure() as $option): ?>
<option value="<?= htmlspecialchars($option->country() ?>"><?= htmlspecialchars($option->country()) ?></option>
<?php endforeach; ?>
Thanks!
$currentCountries = $page->countries()->toStructure();
$englishCountries = $page->content('en')->countries()->toStructure();
Then in your loop, you can find the english or current translation by country, using findBy.
It might make more sense to keep all translations in one structure field in the default language and make the structure non-translatable.
Sorry I don’t quite undertand how I can use findBy here. Can you give me an example?
I used the toArray function to put all english countries in one Array and then use the index to access it in the loop but I’m curious about the findBy method here.
But using an array is fine.