Creating block plugin including css/less

Hi there,

I have written a small language toggle plugin for the sidebar (in OJS 3.0.2) with flags instead of words. I would like to include a small less/css file for this plugin with some basic rules (like size of the icons), but I don’t know where and how to reference this file. Is this even possible?

It would be nice if someone could give me some directions, because I don’t have any experience with this.

Kind regards
Daniela

1 Like

Greetings @UBWolf,

Take a look at this line of code: https://github.com/Vitaliy-1/JATSParserPlugin/blob/master/JatsParserPlugin.inc.php#L116

1 Like

@Vitaliy

Hi Vitality,

thank you, I’ll try that!

Kind regards
Daniela

Hi again,

I’ve put the line of code into my “LanguageFlagsBlockPlugin.inc.php”-file but it there weren’t any changes. Clearly I am doing something wrong. Do I have to reference this somehow in my block.tpl?
I’m sorry to bother you with these certainly easy problems, but after trying for hours I don’t know what to do anymore.

Kind regards
Daniela

Hi,

Do you actually see reference to included css file in the head of the page from the browser?

Hi,

thank you for answering me :slight_smile: no, it doesn’t show. Maybe I am putting it in the wrong function.

Here is my code:

function getContents($templateMgr, $request = null) {
                $templateMgr->assign('isPostRequest', $request->isPost());
                if (!defined('SESSION_DISABLE_INIT')) {
                        $journal = $request->getJournal();
                        if (isset($journal)) {
                                $locales = $journal->getSupportedLocaleNames();

                        } else {
                                $site = $request->getSite();
                                $locales = $site->getSupportedLocaleNames();
                        }
                } else {
                        $locales = AppLocale::getAllLocales();
                        $templateMgr->assign('languageFlagsNoUser', true);
                }

                if (isset($locales) && count($locales) > 1) {
                        $templateMgr->assign('enableLanguageFlags', true);
                        $templateMgr->assign('languageFlagsLocales', $locales);
                        $templateMgr->addStylesheet('languageFlags', 'URL/main.css');
                }
                return parent::getContents($templateMgr, $request);
        }

Kind regards
Daniela

Take a look at the function “register” in my link above (it is the first). The second hook there is for adding your function with links to css in templates.

Hi @Vitaliy

thank you very much! I walked a bit on the path of trial and error, but with your help I finally managed to include the stylesheet.

Thanks again!
Daniela