Documentation for all files associated with TF_Assets.
Requirements
Place config.php in the config folder at application/config/ and tf_assets.php in the libraries folder at /application/libraries/.
The only thing you need activated in CodeIgniter is the url helper.
/config/tf_assets.php
The config file. Pretty self explanatory.
Set the default JS prefix and suffix. This means when adding JS files you can just use 'site', which will equate to 'assets/js/site.js'.
$config['js_prefix'] = 'assets/js/';
$config['js_suffix'] = '.js';
Set the default CSS prefix and suffix. This means when adding CSS files you can just use 'style', which will equate to 'assets/css/style.css'.
$config['css_prefix'] = 'assets/css/';
$config['css_suffix'] = '.css';
Set the default prefix for all content methods. This means when setting content you can just use 'home', which will equate to 'content/home'.
The same principle applies to layouts and partials.
$config['layout_prefix'] = 'layouts/';
$config['content_prefix'] = 'content/';
$config['partial_prefix'] = 'partials/';
/libraries/tf_assets.php
The library file. Here you'll find all the methods you can use within your controller.
function set_layout($layout)
Set the layout to be used
@param string $layout
$this->tf_assets->set_layout('main');
function set_content($content)
Set the content to be used
@param string $content
$this->tf_assets->set_content('home');
function render_partial($path, $data = array(), $return = FALSE)
Renders a partial
@param string $path
@param array $data
@param boolean $return
@return string
$this->tf_assets->render_partial('header', $data);
function render_content($data = array(), $return = FALSE)
Render the content
@param array $data
@param boolean $return
@return string
$this->tf_assets->render_content($data);
function add_css($name, $data = array())
Adds a CSS file to load
@param string $name
@param array $data
$data can take the following values:
| Key | Default Value | Description |
|---|---|---|
| html5 | TRUE | TF Assets automatically assumes your application is html5, and therefore won't put 'type="text/css"' in your link tag. If you want this in, set this to FALSE |
| ignore_suffix | FALSE | If don't want to automatically add the default suffix to your file (say you're using the Google font API, which ends in "?family=PT+Serif:regular"), set this to TRUE |
| group | '' | Places the file into a group. This is used when rendering the assets |
| media | 'screen' | Determines the media type of the css |
$data = array(
'html5' => FALSE
);
$this->tf_assets->add_css('style', $data);
function render_css($group = '', $return = FALSE)
Render the CSS files
@param string $group
@param boolean $return
@return string
$this->tf_assets->render_css('top');
function add_js($name, $data = array())
Add a js file to be loaded
@param string $name
@param array $data
$data can take the following values:
| Key | Default Value | Description |
|---|---|---|
| html5 | TRUE | TF Assets automatically assumes your application is html5, and therefore won't put 'type="text/javascript"' in your script tag. If you want this in, set this to FALSE |
| ignore_suffix | FALSE | If don't want to automatically add the default suffix to your file, set this to TRUE |
| group | '' | Places the file into a group. This is used when rendering the assets |
$data = array(
'html5' => FALSE
);
$this->tf_assets->add_js('style', $data);
function render_js($group = '', $return = FALSE)
Render the js files
@param string $group
@param boolean $return
@return string
$this->tf_assets->render_js('bottom');
function echo_js($javascript, $data = array())
Adds Javascript to be echoed out on the page.
@param string $javascript
@param array $data
$data can take the following values:
| Key | Default Value | Description |
|---|---|---|
| html5 | TRUE | TF Assets automatically assumes your application is html5, and therefore won't put 'type="text/javascript"' in your script tag. If you want this in, set this to FALSE |
| group | '' | Places the file into a group. This is used when rendering the assets |
$this->tf_assets->echo_js('alert("Hello World");', array('group' => "bottom");
function add_data($name, $data)
Add data to be included in the view
@param string $name
@param mixed $data
$this->tf_assets->add_data('username', 'Todd');
function add_multiple_data($data)
Adds an array of data to be included in the view
@param array $data
$data = array(
'username' => 'Todd',
'website' => 'http://toddish.co.uk'
);
$this->tf_assets->add_multiple_data($data);
function flush_data()
Clears the data
$this->tf_assets->flush_data();
function render_layout($return = FALSE)
Renders the layout as a whole
@param boolean $return
@return string
$this->tf_assets->render_layout();