Use only one language for image metadata on a multilanguage site?

Hi there,

I’m currently working on a multi language site, it is in German and English.

I have a meta field set up in my images, so that my client can choose wether or not to show the images in one section of the page. As it seems like radiobuttons are not possible for image options, I am just using a string.

What I need to do is check if there is a string in there which matches ‘y’ (i.e. for yes). I can do this, but it means the user will have to add this string for the image on both languages…I want them to be able to just have to enter ‘y’ on the default language and only have to check for this value in my template.

What I have so far is:

<?php foreach($page->images() as $image): ?>
    <?php if($image->showimage() == 'y'): ?>
        <div class = "content--wrap__img--wrap">
	      <img src="<?= $image->url() ?>" alt="">
        </div>
    <?php endif ?>
<?php endforeach ?>

I have tried this:

<?php foreach($page->images() as $image): ?>
    <?php if($image->content->('de')->showimage() == 'y'): ?>
        <div class = "content--wrap__img--wrap">
	      <img src="<?= $image->url() ?>" alt="">
        </div>
    <?php endif ?>
<?php endforeach ?>

and this:

<?php foreach($site->find($page)->content('de')->images() as $image): ?>
    <?php if($image->showimage() == 'y'): ?>
        <div class = "content--wrap__img--wrap">
	      <img src="<?= $image->url() ?>" alt="">
        </div>
    <?php endif ?>
<?php endforeach ?>

But with no luck :frowning: …is this even possible?

For a file you have to use meta($lang) instead of content($lang):

<?php foreach($page->images() as $image): ?>
    <?php if($image->meta('de')->showimage() == 'y'): ?>
        <div class = "content--wrap__img--wrap">
	      <img src="<?= $image->url() ?>" alt="">
        </div>
    <?php endif ?>
<?php endforeach ?>
1 Like

Nice! Thank you once again for your timely and helpful response. I only had to change it a little to get it to work:

<?php if($image->meta(‘de’)->showimage() == ‘y’): ?>

(the language is an argument for the function, not an operator)