Theme クラス

The Theme class provides theming to your application.

Asset support

Every Theme class instance has it's own instance of the Asset class, to make it easy to load assets from the theme. The Asset instance is populated with the asset paths of both the active and the fallback theme, which will provide the same fallback features for your assets as you have for other theme elements like templates and views.

Example:

// load an asset using the default theme instance
echo \Theme::instance()->asset->css('bootstrap.css');

Advanced configuration

The methods active(), fallback(), get_info() and load_info() by default allow you to pass a string with the name of an installed theme. These methods allow you to pass an theme definition array instead, which makes it possible to pass extra configuration information.

The following theme variables are defined:

パラメータ デフォルト 説明
name string required The name of the theme. This must match to a folder in the path specified.
path string required The path of the theme. This must include the name of the theme, and end with a directory separator.
asset_base string optional The base path to the assets of this theme, relative to the application DOCROOT. If outside the DOCROOT, the path should be fully qualified. It should end with a directory separator. If not specified, it will be constructed from the given theme path, the configured assets_folder, and the configured base_url.
info array optional The theme's information array. If not defined, it will be created from the information in the theme info file.
find_file boolean optional If set to true, the Finder::search() method will be used to locate view files and theme info files.

Example:

// standard usage: create an instance and set the active theme
$theme = \Theme::forge();
$theme->active('darkglow');

// advanced usage
\Config::load('theme', true, false, true);
$config = \Config::get('theme', false);

// override some config values
$config['info_file_name'] = 'setup.info';
$config['info_file_type'] = 'ini';

// create the theme instance
$theme = \Theme::forge($config);

// set the active theme
$theme->active(
	array(
		'name' => 'darkglow',
		'path' => APPPATH.'themes'.DS.'darkglow'.DS,
		'asset_base' => '/themes/darkglow/assets/',
		'find_file' => true,
	)
);