Translate multiple field options and display them on page

Hi there,

I’m using the following code to display selected field options on my page:

<?php foreach($project->categories()->split(',') as $category): ?>
<span><?= $category ?></span>
<?php endforeach ?>

But now I want to have those options translated. Multi-language already set up.
I have tried to figure it out by using a translation *.yml and the documentation but have been unsuccessful.

Hope somebody can help me with that. Cheers!

Yes, you need to do it exactly as described in the docs.

Could you post the code that doesn’t work, including the yaml file, the template code and an example field value as saved in your content file.

The part I could not figure out is how to call and split the translated options instead of calling the ones in the text file as is happening at the moment with the code above.

You don’t need tochange any of that but just use the l() method and pass the category as parameter

<?php foreach($project->categories()->split(',') as $category): ?>
<span><?= l($category) ?></span>
<?php endforeach ?>
1 Like

Ah, oh. Didn’t think it was that easy. Whoops.

Thank you!