<commit_before>View Components Cookbook
========================

## How to avoid including css & js files required by components if they are already included to page layout (not via view-components)

Use following methods:

* ResourceManager::ignoreCss() 
* ResourceManager::ignoreJs()

Each of listed methods accepts one argument with resource URL or alias or array of URLs or aliases. 

### Example
```php
Services::resourceManager()
    ->ignoreCss(['boostrap', 'bootstrap-datepicker'])
    ->ignoreJs(['bootstrap', 'bootstrap-datepicker']);
```

If you need to ignore css & js resources on concrete page, place this code before components rendering.

If you need to ignore css & js resources on all pages of your application, there are two options:

a. Place this code to your application bootstrap.

b. Register service provider in view-components bootstrap. This will allow to avoid execution of mentioned code on pages that don't use view-components and console commands that share same application bootstrap.


ServiceProvider class:

```php
namespace MyApp;

use ViewComponents\ViewComponents\Service\ServiceContainer;
use ViewComponents\ViewComponents\Service\ServiceId;
use ViewComponents\ViewComponents\Service\ServiceProviderInterface;
use ViewComponents\ViewComponents\Resource\ResourceManager;

class MyServiceProvider implements ServiceProviderInterface
{
    public function register(ServiceContainer $container)
    {
        $container->extend(ServiceId::RESOURCE_MANAGER, function (ResourceManager $resourceManager) {
            $resourceManager
                ->ignoreCss(['boostrap', 'bootstrap-datepicker'])
                ->ignoreJs(['bootstrap', 'bootstrap-datepicker']);
            return $resourceManager;
        });
    }
}
```

Service provider registration (place it to your application bootstrap)

```php
use MyApp\MyServiceProvider;
use ViewComponents\ViewComponents\Service\Bootstrap;

Bootstrap::registerServiceProvider(ServiceProvider::class);

```

If you don't want to create class for service provider, you can use anonymous function in view-components bootstrap:


```php<commit_msg>Update cookbook.md<commit_after>View Components Cookbook
========================

## How to avoid including css & js files required by components if they are already included to page layout (not via view-components)

Use following methods:

* ResourceManager::ignoreCss() 
* ResourceManager::ignoreJs()

Each of listed methods accepts one argument with resource URL or alias or array of URLs or aliases. 

### Example
```php
Services::resourceManager()
    ->ignoreCss(['boostrap', 'bootstrap-datepicker'])
    ->ignoreJs(['bootstrap', 'bootstrap-datepicker']);
```

If you need to ignore css & js resources on concrete page, place this code before components rendering.

If you need to ignore css & js resources on all pages of your application, there are two options:

a. Place this code to your application bootstrap.

b. Register service provider in view-components bootstrap. This will allow to avoid execution of mentioned code on pages that don't use view-components and console commands that share same application bootstrap.


ServiceProvider class:

```php
namespace MyApp;

use ViewComponents\ViewComponents\Service\ServiceContainer;
use ViewComponents\ViewComponents\Service\ServiceId;
use ViewComponents\ViewComponents\Service\ServiceProviderInterface;
use ViewComponents\ViewComponents\Resource\ResourceManager;

class MyServiceProvider implements ServiceProviderInterface
{
    public function register(ServiceContainer $container)
    {
        $container->extend(ServiceId::RESOURCE_MANAGER, function (ResourceManager $resourceManager) {
            $resourceManager
                ->ignoreCss(['boostrap', 'bootstrap-datepicker'])
                ->ignoreJs(['bootstrap', 'bootstrap-datepicker']);
            return $resourceManager;
        });
    }
}
```

Service provider registration (place it to your application bootstrap):

```php
use MyApp\MyServiceProvider;
use ViewComponents\ViewComponents\Service\Bootstrap;

Bootstrap::registerServiceProvider(MyServiceProvider::class);

```

If you don't want to create class for service provider, you can use anonymous function in view-components bootstrap:


```php
{'fraction_non_alphanumeric': 0.09333958724202626, 'fraction_numerical': 0.0, 'mean_word_length': 4.899031811894883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4068888', 'n_tokens_mistral': 1030, 'n_tokens_neox': 979, 'n_words': 386}