Jump to content

Recommended Posts

Posted

I try to display flag icons in Page templates. E. g. for German

<i class="ipsFlag ipsFlag-de"></i>

It does not work and displays nothing. The reason is, that I do have only one language installed. In system/Dispatcher/Standard.php you do not load a CSS in this case:

if ( \count( \IPS\Lang::languages() ) > 1 )
{
	\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'flags.css', 'core', 'global' ) );
}

What is the reason for not loading this CSS on the projects with only one language installed? 

Posted
23 minutes ago, Sonya* said:

What is the reason for not loading this CSS on the projects with only one language installed? 

The flags are used for the language selector dropdown. If there is just one language, there is no language drop-down and no need to load the flags. 

Posted (edited)
6 minutes ago, opentype said:

no need to load the flags

Use case

I have created a Pages database similar to Providers. This database has a select field, where the provider can choose a language for communication, e.g. German, Russian, Ukrainian.

I would like to display their language selection in template as flags.

Edited by Sonya*
Posted
37 minutes ago, Sonya* said:

Use case

I have created a Pages database similar to Providers. This database has a select field, where the provider can choose a language for communication, e.g. German, Russian, Ukrainian.

I would like to display their language selection in template as flags.

Just include the flags.css file manually

Posted

Sure. In this case, you just call the array_merge code from the database template where you need the flags. 

{{\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'flags.css', 'core', 'global' ) );}}

 

Posted
3 minutes ago, Daniel F said:

Just include the flags.css file manually

What would happen if I install another language in the future. Will this CSS be loaded twice? 🤔

Posted

What he said.

If you're still worried about it you can just do this in your code:

if ( \count( \IPS\Lang::languages() ) == 1 )
{
	\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'flags.css', 'core', 'global' ) );
}

 

Check if there is only 1 language and then add the CSS file. If you ever add a new language the count will not be 1 and the default code you pasted will kick in instead.

  • Recently Browsing   0 members

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