Sonya* Posted April 13, 2022 Posted April 13, 2022 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?
opentype Posted April 13, 2022 Posted April 13, 2022 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.
Sonya* Posted April 13, 2022 Author Posted April 13, 2022 (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 April 13, 2022 by Sonya*
Daniel F Posted April 13, 2022 Posted April 13, 2022 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 Sonya* 1
opentype Posted April 13, 2022 Posted April 13, 2022 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' ) );}} Sonya* 1
Sonya* Posted April 13, 2022 Author Posted April 13, 2022 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? 🤔
opentype Posted April 13, 2022 Posted April 13, 2022 Not sure, but if you are worried about it, you could use the language count from your first post to make sure the code is only used with one language present. Sonya* 1
teraßyte Posted April 13, 2022 Posted April 13, 2022 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. Sonya* 1
Recommended Posts