You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2023-09-15 20:05:32

Johan Romo
Member
From: Mexico City
Registered: 2022-10-27
Posts: 13

[Solved] Use Plugin's CSS

Hello there.

My plugin display a new entry to tickets left menu, this use HTML and tag <style> to show the tables, buttons, labels, etc for my plugin:

<?php 

include_once ("../../../../inc/includes.php");


class PluginChooseCountriesStatesCities extends CommonGLPI
{
     /**
     * This function is called from GLPI to allow the plugin to insert one or more item
     *  inside the left menu of a Itemtype.
     */
    function getTabNameForItem(CommonGLPI $item, $withtemplate=0)
    {
        return self::createTabEntry('City Selection'); /*New Tab's Name*/
    }
 
    /**
     * This function is called from GLPI to render the form when the user click
     *  on the menu item generated from getTabNameForItem()
     */
    public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0)
    {
?>
       

<head>

<style>

             MY STYLE

</style>

</head>
<body>
...
</body>

<?php
        return true;
    }
}
?>

All works perfect, the only problem is that some icons and boxes from the other default options in the main ticket page does not render correctly, this can be fix refreshing the page, but I want to add my plugin's style correctly to display it with any problem with the GLPI's style.

I think that GLPI's style and My Plugin's style are in conflict, so there are problems to render correctly items.

Thank you

Last edited by Johan Romo (2023-10-20 19:53:07)

Offline

#2 2023-09-15 21:05:50

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: [Solved] Use Plugin's CSS

Don't use any closing PHP tags to embed HTML directly. This isn't WordPress tongue.

If you have styles that need loaded, feel free to put them in a CSS file in your plugin and then load that CSS in your plugin's init function using the "add_css" hook.
To display HTML content, use "echo" statements (easiest option) or, if you are in GLPI 10 or later, create a Twig template file in a "templates" folder in your plugin files and call "Glpi\Application\View\TemplateRenderer::getInstance()->render()" with the relative path. It would be "@" + the plugin folder name + path relative to the templates folder. You do not include "templates" in the path.

The majority of GLPI plugins are open source, so they can be used as a reference point. There is also an example plugin which could be a good start as a reference, if not completely functional.
https://plugins.glpi-project.org/#/
https://github.com/pluginsGLPI/example


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#3 2023-10-20 19:51:48

Johan Romo
Member
From: Mexico City
Registered: 2022-10-27
Posts: 13

Re: [Solved] Use Plugin's CSS

Thank you big_smile

Offline

Board footer

Powered by FluxBB