About Pi Downloads Documentation Plugins Developer Forum Issues

pi.util.Import

Summary

Includes a JS or CSS file to the page with a synchronous request.

Syntax

pi.util.Import(file url,fileType (optional));

Usage Example

>>> pi.util.Import("foo.js");
>>> pi.util.Import("../style/hello.css");
If the given file extension URL is not js, pi will accept the source as a CSS file.If this causes problems, there can be sent a "js" string as a second parameter.
>>> pi.util.Import("scripts/dynamicJavascript.php","js");

Examples

Example #1: Import a script file with the message function and message.css to the created script.

Source files of the above example:

../../examples/hello.html

<div id="message">
</div>

../../examples/hello.js

pi.util.Import("../../examples/message.js");
pi.util.Import("../../examples/message.css");
message("Hello World!");

../../examples/message.js

function message(_text){
	pi.get("message").innerHTML = _text;
}

../../examples/message.css

#message { border:5px solid blue; padding:10px; background:black; color:white; }