Jump to content

Recommended Posts

Posted

Good morning,

I started to create a new website. This website must be multi-language.
I want to use icons to select the language. So i created a new fiel and added this to the language Template.

But now:

1. Select default Language (here english) alle Icons are shown

2. Select german language i only get the url of the german icon

<ul class="langList DropContent" style="background-color: #<?php echo $themecolor ?>">
<?php
foreach($languages as $language) {
echo '<a hreflang="'.$homepage->getLanguageValue($language, 'name').'" href="'.$page->localHttpUrl($language).'"><li>'.$language->title.'<img src="'.$language->lang_icon->url.'" alt="'.$language->title.'" /></li></a>';
}
?>
</ul>

lang_german.JPG

lang_english.JPG

Posted

What are its contents inside the english and german languages?

What its the url that echo $language->lang_icon->url returns?

May be something in german language its causing the english flag to not having the right path

Posted

Probably not the cause of your problem, but it is not valid HTML to wrap a link around a list item. The only element that can be a direct child of <ul> is <li>.

 

Posted

If you're just get the path than you're getting the field value in outputformatting off mode. I'd suggest using the options posted here: 

 

Posted

Thanks a lot trying to help me....

i solved the problem. I deleted the field lang_icon an created a new one with a different name. renamed the images.  and it work. don't know why, maybe pw have problems with the fieldname or the filename.

Posted

I would use a CSS class and CSS background image for the icon, no need for an extra field.

  • Like 1
  • 2 years later...
Posted

Yes, an old post, but if you are having the same problems as @ChriWolf

with the primary icon not showing when you swap to the 2nd language.

It seem to fail when the field is called "language_icon", but works with the field called e.g. "flag_icon"...so omit the use of the word "language" for your image field name.

 

  • 1 month later...
Posted

Sorry...this still wasn't working correctly, but this fixed it

$thumb = $language->getUnformatted('flag_icon')->first;

<?php
foreach($languages as $language) {
if(!$page->viewable($language)) continue; // is page viewable in this language?
if($language->id == $user->language->id) {
echo "<span class='currentlang'>";
} else {
echo "<span>";
}
$url = $page->localUrl($language); 
$hreflang = $homepage->getLanguageValue($language, 'name'); 
$thumb = $language->getUnformatted('flag_icon')->first;	                            
echo "<a hreflang='$hreflang' href='$url' title='$language->title'><img src='{$thumb->url}' alt='$language->title'/></a></span>";
}
?>

 

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...