Jump to content

How to add field called flagicon to Setup >Languages Section?


Kemal
 Share

Recommended Posts

Hi,

i am using multi language profile. I would like to use flagicon instead of the language name on top to switch languages.

So i would like to use $language->flagicon instead of $language->title.

On Setup>Languages>Add New Language  is it possible to add imagefield or text filed which store imagepath?

so i can call it as i said above.

If is there any other way to do that help me pls.

Link to comment
Share on other sites

Like everything else, languages are just pages that have their own template. Under Templates, select “show system templates”. There will be a template called “language” which you can modify like any other. Just add your field to it and it will work.

Link to comment
Share on other sites

cool, i did not know show system templates

i try to add image field and upload a flag icon the try to call from home template

$language->icon->url but it just give the file name not url so i delete filed and i used text field to store icon path 

it worked this way thanx

i just wondering why cant i get the url of the image file with $language->icon->url 

Link to comment
Share on other sites

Must be a problem with your image field. Have you tried $language->icon->first->url? $language->icon can be different things depending on how you set up the field.

In the field settings for icon, look under “Formatted Value”. There you can choose what you want $language->icon to return.

Link to comment
Share on other sites

  • 2 months later...

Must be a problem with your image field. Have you tried $language->icon->first->url? $language->icon can be different things depending on how you set up the field.

In the field settings for icon, look under “Formatted Value”. There you can choose what you want $language->icon to return.

Thanks for this. Noticed the same problem as Kemal.

$flag = $language->image->first->url;

did the trick.

Link to comment
Share on other sites

@beluga, @kamal: it's a Feature not a bug. If you set "max files" to 1 in your field config it should work without "first->". Otherwise it's not possible to know which image's url you want to receive as there could be more than one uploaded.

Link to comment
Share on other sites

  • 1 year later...

Hello.  I have a very strange problem in regards to this topic.

I have added an image field to language template (simple image, named one_image), formatted to be Single item, attached to each language 1 image (flag) and in the front end I am accessing this field in a loop like this:

        foreach($languages as $language) {
            $url = $page->localUrl($language); 
            $hreflang = $homepage->getLanguageValue($language, 'name'); 
            echo "<a hreflang='$hreflang' href='$url'>$language->title <img src='".$language->one_image->url."' /></a>";
        }

The strange part is that is that is not showing this flag image for the default language (first language, ro) when I select another language (en, fr)... The images are uploaded, I have checked in the DB and admin area. In the front end, for the default language, it is showing only the folder path the image, not outputting the actual file name, for example "/site/assets/files/1010/" .

I have attached and detached 2 times this field from the language template, the results are the same. I have also tried different formatting for this image field, nothing works, same results...

I am using processwire 3.0.36. I have also attached 2 printscreens.

Any advice ?

 

1.png

2.png

Link to comment
Share on other sites

  • 3 months later...
On 14/10/2016 at 11:09 AM, adrianromega said:

The strange part is that is that is not showing this flag image for the default language (first language, ro) when I select another language (en, fr)... The images are uploaded, I have checked in the DB and admin area. In the front end, for the default language, it is showing only the folder path the image, not outputting the actual file name, for example "/site/assets/files/1010/" .

I'm experiencing the same problem as @adrianromega. My actual code is:

$savedLanguage = $user->language;
	foreach($languages as $language) {
		if($language->id == $savedLanguage->id) continue;
		if(!$page->viewable($language)) continue;
		$user->language = $language;
		$flag = $language->flag->first->url;
		echo "<li><a href='$page->url'><img src='$flag' alt=''>$language->title</a></li>";
	}
$user->language = $savedLanguage;

In the default language the "flag" field image is showing correctly, where nothing appears in the english section of the site.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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