FUEL CMS User Guide : Version 1.4


Assets

The Assets module allows you to manage the images, CSS, and javascript for your sites. You must set the asset folders you want managed to have writable permissions. Because assets are saved on the file system and not in a database, you can use an FTP client to manage the assets as well.

Uploading Assets

To upload assets through the CMS, you can use the Upload button in the Assets module. The upload page provides the following upload options:

Incorporating Into Your Own Module

You can incorporate assets into your own modules by specifying a field type of asset in your model's form_fields method. This will actually open up the assets module in a window for you to upload one or more files. This field type provides a couple parameters to control things including:

function form_fields($values = array(), $related = array())
{
	$fields = parent::form_fields($values, $related);
	$fields['image_field'] = array('type' => 'asset', 'folder' => 'my_folder', 'overwrite' => FALSE);
	return $fields;
}

Field names that end with "img" or "image" will automatically be assigned a field type of asset.

Using Assets in Pages

To incorporate assets in your pages, use one of the asset_helper functions like js(), css() or img_path. Below are some examples:

// using normal PHP syntax if used in a static view file 
<img src="<?php echo img_path('my_img.jpg')?>" alt="My Image" />

// using the templating syntax if used in field in the CMS
<img src="{img_path('my_img.jpg')}" alt="My Image" />

Optimizing Assets

FUEL provides a way to optimize JS and CSS files by condensing their output into a single file. This can be done "on the fly" by changing the assets_output configuration parameter to TRUE (or one of the other values listed in the configuration parameters comment). This will combine all the files called in a single js() and css() function call and optimize them by removing whitespace and adding gzip compression.

Must have the assets/cache/ folder writable for the assets_output compression to work "on the fly".


Alternatively, you can generate these files via command line by using FUEL's "build" functionality like so:

// js
>php index.php fuel/build/app/js/plugins:plugins

// css
>php index.php fuel/build/app/css/plugins:plugins

The above will grab all the javascript files located in the main assets/js/plugins folder (the segment "app" refers to the main assets directory) and create a file called plugins.js in the assets/js folder. The file name is denoted after the colon. If no file name is provided then it will default to main.min.js or main.min.css respectively.