Topics

JavaScript in ImpressPages

Adding JavaScript to your theme

All JS of the theme should go to the folder /Theme/MyTheme/assets. Use <?php ipAddJs('assets/filename.js'); ?> function in your theme's layout file to add JS you need. Make sure you add this function above ipJs() function. Otherwise your JS won't be added. 

Adding JavaScript in your plugin

To add JavaScript using a plugin, catch ipBeforeController event and use the same ipAddJs('assets/filename.js') function. Just this time JavaScript file has to be in Plugin/MyPlugin/assets/ directory.

jQuery

ImpressPages adds 2.x version of jQuery by default. If your plugin or theme needs jQuery, just use it.

If you will add your own version of jQuery, many things will be broken. Use this TIP if you desperately need to remove or replace original jQuery.

Bootstrap

In admin mode ImpressPages uses Bootstrap. So Bootstrap JavaScript is also there automatically. Just use it for any admin functionallity you may need.

If you need Bootstrap for public visitors, add Bootstrap, but only in non admin mode. If you will add it in admin mode, you will break your plugin and / or ImpressPages.

Here is an example on how to add your own Bootstrap only in public mode. Use this code in your theme's layout before ipJs function or ipBeforeController event of your plugin.

<?php
if ( ! ipAdminId()) {
    ipAddJs('assets/yourOwnBootstrap.js');
}
comments powered by Disqus