ChriWolf Posted July 28, 2016 Posted July 28, 2016 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>
clsource Posted July 28, 2016 Posted July 28, 2016 Seems ok. The lang_icon field is set as multilanguage? maybe the contents are set in english but in german are wrongly set.
ChriWolf Posted July 28, 2016 Author Posted July 28, 2016 hank you for your answer, The fieldtype is an 'image'. i can't find any MultiLang-Attributes for the file in the backend.
clsource Posted July 28, 2016 Posted July 28, 2016 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
ChriWolf Posted July 28, 2016 Author Posted July 28, 2016 I only get the path but not the filename. in the images you'll see the rendered html code.
Robin S Posted July 28, 2016 Posted July 28, 2016 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>.
LostKobrakai Posted July 28, 2016 Posted July 28, 2016 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:
ChriWolf Posted July 28, 2016 Author Posted July 28, 2016 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.
tpr Posted July 28, 2016 Posted July 28, 2016 I would use a CSS class and CSS background image for the icon, no need for an extra field. 1
dab Posted December 12, 2018 Posted December 12, 2018 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.
dab Posted January 14, 2019 Posted January 14, 2019 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>"; } ?>
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now