Writing a controllerRegenerating DAOs

Adding JS and CSS files

There are several techniques available, depending on your need. If you want to add JS / CSS files on every page, you will be using dependency injection to inject JS/CSS files directly in the template. If you want to add JS / CSS files only on some pages, you will be using the code approach.

In every case, JS/CSS addition is managed by the WebLibraryManager.

The WebLibraryManager is a class that references all the JS libraries and CSS files that are included in a web page. JS files and CSS files are grouped together in WebLibary objects.

On every page

The WebLibraryManager comes with a default instance defaultWebLibraryManager, that is used by the template.

Web library manager instance

You just need to add a new WebLibrary to the instance list.

Then, edit this weblibrary, and add the JS and CSS files you want to include.

Web library instance

_Note:_ Do not start the JS or CSS file path with a /. That way, the path is relative to the ROOT_URL (the root of your web application). You can also enter a full path (http://...) if you want to use hosted libraries, CDN, etc...

On a single page

Sometimes, you only need to import JS or CSS files in one page. In this case, you will perform the addition using PHP code. This code will typically go into your controller.

    new WebLibrary(array("javascript/file1.js", "javascript/file2.js"),
            array("css/style1.css", "css/style2.css"))  

This codes create a new WebLibrary and adds it to the WebLibraryManager. The WebLibrary takes an array of Javascript files as first argument, and an array of CSS files as second argument.

Writing a controllerRegenerating DAOs

Found a typo? Something is wrong in this documentation? Just fork and edit it!