public static method

Calculates the web-accessible path to a static asset, usually a JavaScript, CSS or image file.


  • string $path

    The path to the asset, relative to the given $types path and without a suffix. If the path contains a URI Scheme (eg. http://), no path munging will occur.

  • string $type

    The asset type. See Media::$_assets or Media::assets().

  • array $options

    Contains setting for finding and handling the path, where the keys are the following:

    • 'base': The base URL of your application. Defaults to null for no base path. This is usually set with the return value of a call to env('base') on an instance of lithium\action\Request.
    • 'check': Check for the existence of the file before returning. Defaults to false.
    • 'filter': An array of key/value pairs representing simple string replacements to be done on a path once it is generated.
    • 'paths': An array of paths to search for the asset in. The paths should use Text::insert() formatting. See Media::$_assets for more.
    • suffix: The suffix to attach to the path, generally a file extension.
    • 'timestamp': Appends the last modified time of the file to the path if true. Defaults to false.
    • 'library': The name of the library from which to load the asset. Defaults to true, for the default library.



Returns the publicly-accessible absolute path to the static asset. If checking for the asset's existence ($options['check']), returns false if it does not exist in your /webroot directory, or the /webroot directories of one of your included plugins.


This method can be filtered.


	public static function asset($path, $type, array $options = []) {
		$options = static::_assetOptions($path, $type, $options);
		$params = compact('path', 'type', 'options');

		return Filters::run(get_called_class(), __FUNCTION__, $params, function($params) {
			$path = $params['path'];
			$type = $params['type'];
			$options = $params['options'];
			$library = $options['library'];

			if (preg_match('/^(?:[a-z0-9-]+:)?\/\//i', $path)) {
				return $path;
			$config = Libraries::get($library);
			$paths = $options['paths'];
			$config['default'] ? end($paths) : reset($paths);
			$options['library'] = basename($config['path']);

			if ($options['suffix'] && strpos($path, $options['suffix']) === false) {
				$path .= $options['suffix'];
			return static::filterAssetPath($path, $paths, $config, compact('type') + $options);