extends | title | group | prev | next | order |
---|---|---|---|---|---|
docs |
Asset |
Architecture |
integrating-advanced-custom-fields |
config |
1 |
The Tonik\Gin\Asset\Asset
class provides simple API for retrieving information and details about theme asset files. You can easily pull their URLs, directory paths or check if actually exist.
Asset requires the Tonik\Gin\Foundation\Config
class to be injected with paths
and directories
properties set up.
use Tonik\Gin\Asset\Asset;
use Tonik\Gin\Foundation\Config;
$config = new Config([
'paths' => [
'directory' => get_template_directory(),
'uri' => get_template_directory_uri(),
],
'directories' => [
'assets' => 'resources/assets',
'public' => 'public',
]
]);
$asset = new Asset($config);
Now, you can set a path to the file you are looking for. This path should be relative to the public
directory.
$asset->setFile('js/app.js');
Gets a relative path of an asset to the project root directory.
$asset->getRelativePath();
// 'public/js/app.js'
Gets URI to the asset on your server.
$asset->getUri();
// 'http://website.com/wp-content/themes/<theme-name>/public/js/app.js'
Gets full directory path to the asset on your server.
$asset->getPath();
// 'website/directory/wp-content/themes/<theme-name>/public/js/app.js'
You can check if asset file actually exists with fileExist
method.
$asset->fileExists();
// true or false