Mecha CMS

Add extra functionality to the core engine.

Assets

Author: Taufik Nurrohman · 150 Views

Tweet

Add, remove, append, prepend and replace asset files from/to the HTML output without touching the shield files.

Table of Content

This extension works by looking for two special places in the HTML document, i.e. right before the </head> and </body> tag. This extension will process all assets that you were added to the hook storage and then spit them out into that places:

<!DOCTYPE html>
<html dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Lorem Ipsum</title>
  •</head>
  <body>
    <p>Lorem ipsum dolor sit amet.</p>
  •</body>
</html>

The first place is generally used to insert CSS assets, while the second place is used to insert JavaScript assets.

Usage 

To append CSS assets to the <head> section, write this code in an index.php file:

Asset::set('path/to/file.css');

To append JavaScript assets to the <body> section, write this code in an index.php file:

Asset::set('path/to/file.js');

Once added, this extension will process the file path and then will output them into the HTML page as <link> tags for CSS files and <script> tags for JavaScript files.

Note: This extension will ignore files that does not exist.

Related: Class Asset

0 Comments

No comments yet.