Jump to content

Recommended Posts

Posted (edited)

I'm trying to loop through languages to see what active languages a certain page has in PW 3.0.229. I can't get anything to work. I've tried three ways (see below)

For example. I've got a page with 3 active languages out of 14:

image.thumb.png.caaa4e76d082604c1e010dd72cb3c262.png

I've set it to redirect to default if accessed with missing language, and this works fine

image.thumb.png.e861bec602dfc977e65ef270f88d1df1.png

Now, how do I list the languages that are active? So far I've tried these three ways:

<?php
 	$a = My current Page;

	$a->status; // = always 1
?>


<?php foreach(wire('languages') as $language):?>
	<?php
		wire('user')->language = $language;
	?>
	<?=$a->viewable()?> <-- All true
<?php endforeach?>


<?php foreach(wire('languages') as $language):?>
	<?php
		wire('user')->language = $language;
	?>
	<?=$a->is("status$language")?> <-- all empty
<?php endforeach?>

thanks!

Edited by joe_g
  • joe_g changed the title to I don't manage to list what languages that are set to 'active'
Posted (edited)

I wonder if the answer is not in the screenshot you shared:

"This setting does not apply if the page is editable to the user as it will always be available for preview purposes"

Do you see your issue happening as well when you are not logged in ?

Edit: also I think you should use https://processwire.com/api/ref/page/get-languages/ to loop through active languages

Edited by monollonom
Posted

Ah perfect. I forgot to mention that I get the same result logged out as well as logged in. But it doesn't matter since $a->getLanguages() works fine.

thanks!

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...