Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted April 13, 20222 yr 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?
April 13, 20222 yr 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.
April 13, 20222 yr Author 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, 20222 yr by Sonya*
April 13, 20222 yr 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
April 13, 20222 yr 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' ) );}}
April 13, 20222 yr Author 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? 🤔
April 13, 20222 yr 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.
April 13, 20222 yr 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.