Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.44 KB

README.md

File metadata and controls

58 lines (40 loc) · 1.44 KB

Using assets

Assets are files that are not processed by Webpack. They are copied directly to the output folder. This includes images, fonts, and any other files that you want to use in your project.

To use an asset, you need to import it from JavaScript or CSS.

file: ./resources/views/layout/main.php

<?php

declare(strict_types=1);

use Yii\Assets\SweetAlert2Dev;

/**
 * @var \Yiisoft\Assets\AssetManager $assetManager
 */

// Register the asset bundle with a asset manager component.
$assetManager->register(SweetAlert2Dev::class);

// Set parameters for the registered asset bundle a view component.
$this->addCssFiles($assetManager->getCssFiles());
$this->addCssStrings($assetManager->getCssStrings());
$this->addJsFiles($assetManager->getJsFiles());
$this->addJsStrings($assetManager->getJsStrings());
$this->addJsVars($assetManager->getJsVars());

Registering the Asset Bundle via container configuration

Alternatively, you can register the asset bundle through the container configuration.

file: ./config/params.php

<?php

declare(strict_types=1);

use Yii\Assets\SweetAlert2Cdn;

return [
    'yiisoft/assets' => [
        'assetManager' => [
            'register' => [
                SweetAlert2Cdn::class,
            ],
        ],
    ],
];

Using npm packages

You can install npm packages fxpio/foxy, and they will be available in the node_modules directory.