When creating a plugin, you'll often include css and/or javascript to make it function properly. There are a number of options for how to do this which we'll explain and show example of below.

Add With Addon.ini

It is possible to add elements to the <head>...</head> portion of gpEasy pages with nothing more than a line or two of code in the Addon.ini file of your plugin.

html_head = '<link rel="stylesheet" href="{$addonRelativeCode}/style.css" type="text/css" />';
This line of code will add a link for the style.css file of your plugin to all gpEasy pages.

 

Note the use of {$addonRelativeCode}. This is one of a few variables available in the Addon.ini file.

Add to Combine.php

To make gpEasy pages load faster, javascript and css files are combined into two compressed files before being sent to the user. Your plugin can add files to these compressed files in a number of ways.

Hooks

For a plugin to add css and js files to the combined and compressed files, it needs to add an entry to the $page->css_admin, $page->css_user or $page->head_js arrays. This can be done in a number of ways and below is an example of how to do so using the GetHead hook. (The GetHead hook will be available in 2.0b3.)

YourPlugin/Addon.ini

...
[GetHead]
script = script.php
method = plugin_function

 

YourPlugin/script.php

function plugin_function($js_files){
	global $addonRelativeCode,$page;
	$page->head_js[] = $addonRelativeCode.'/javascript.js';
}

Because gadgets are often called after the <head> section of a page is generated, the GetHead hook is the best way to add javascript and css files to the combined outputs.

 

$page->css_admin vs $page->css_user The only difference between $page->css_admin or $page->css_user is the order in which they are used. CSS files in the $page->css_user array will be loaded before other gpEasy specific css files including the css file for the current theme. CSS files in the $page->css_admin array are loaded last giving the css rules in these files higher importance in the document. If you're not sure which one to use, start with $page->css_user, it's very easy to change it down the road.

News

Typesetter 5.1
8/12/2017

Typesetter 5.0.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More

Over 8 Times Faster Than Wordpress
5/3/2016

We've known for a long time that Typesetter is fast. It's something we take pride ... Read More

More News

creisi productions

Dienstleistungen von creisi productions, Luzern (Schweiz): Konzeption, Planung und Erstellung Ihres Internet-Auftritts, Betreuung und Aktualisierung Ihrer Website, Programmierun...

Find out more about our Provider Spotlight

Log In

  Register