PHPackages                             nystudio107/craft-autocomplete - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. nystudio107/craft-autocomplete

ActiveYii2-extension[Templating &amp; Views](/categories/templating)

nystudio107/craft-autocomplete
==============================

Provides Twig template IDE autocomplete of Craft CMS &amp; plugin variables

1.12.2(1y ago)44204.4k—8.1%413MITPHP

Since Aug 9Pushed 1y ago2 watchersCompare

[ Source](https://github.com/nystudio107/craft-autocomplete)[ Packagist](https://packagist.org/packages/nystudio107/craft-autocomplete)[ GitHub Sponsors](https://github.com/khalwat)[ RSS](/packages/nystudio107-craft-autocomplete/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (18)Used By (13)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/022f7ede8b0648ad6224fa9938b3547911c486bd71e24c70525f2e28605aee39/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f63726166742d6175746f636f6d706c6574652f6261646765732f7175616c6974792d73636f72652e706e673f623d7631)](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/?branch=v1) [![Code Coverage](https://camo.githubusercontent.com/690f29a9a11d6a4c7ca70bb0c4793fa1e475b0c144dec320b88a8052f540cd55/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f63726166742d6175746f636f6d706c6574652f6261646765732f636f7665726167652e706e673f623d7631)](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/?branch=v1) [![Build Status](https://camo.githubusercontent.com/aa18f3d0ad44d5173b77bb89edb437f097b63f33dc37d51d89676dfa80142092/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f63726166742d6175746f636f6d706c6574652f6261646765732f6275696c642e706e673f623d7631)](https://scrutinizer-ci.com/g/nystudio107/craft-autocomplete/build-status/v1) [![Code Intelligence Status](https://camo.githubusercontent.com/b73584cb8f2c119a2660b0c8840ed1344b8e4508fd7e0a27b5dc49bf8828116a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f63726166742d6175746f636f6d706c6574652f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d7631)](https://scrutinizer-ci.com/code-intelligence)

Autocomplete for Craft CMS 3.x, 4.x &amp; 5.x
=============================================

[](#autocomplete-for-craft-cms-3x-4x--5x)

Provides Twig template IDE autocompletion for Craft CMS and plugin/module variables and element types.

Works with PhpStorm provided the [Symfony Support plugin](https://plugins.jetbrains.com/plugin/7219-symfony-plugin) is installed. VSCode currently does not support intellisense for Twig extensions.

> While Craft [3.7.8](https://github.com/craftcms/cms/blob/v3/CHANGELOG.md#L1636) added autocompletion for Craft’s global Twig variables, this does not include autocompletion for plugins and modules that provide their own variables or element types.

[![demo](https://user-images.githubusercontent.com/57572400/126911028-7d7d06dd-c60f-42b9-ae42-95d5f078a229.gif)](https://user-images.githubusercontent.com/57572400/126911028-7d7d06dd-c60f-42b9-ae42-95d5f078a229.gif)

Requirements
------------

[](#requirements)

This package requires Craft CMS 3.x, 4.x, or 5.x

Usage
-----

[](#usage)

1. Install the package using composer, adding it to `require-dev`:

```
composer require nystudio107/craft-autocomplete --dev
```

2. Ensure that the [Symfony Support plugin](https://plugins.jetbrains.com/plugin/7219-symfony-plugin) for PhpStorm is installed and enabled by checking the **Enabled for Project** checkbox in the Symfony plugin settings.
3. Ensure that `devMode` is enabled.
4. Visit the Craft site on which the package is installed to generate the autocomplete classes in `storage/runtime/compiled_classes/` or run the following console command.

```
php craft autocomplete/generate
```

Once your IDE indexes the autocomplete classes, autocompletion for Craft and all plugins and modules will immediately become available in your Twig templates.

[![screenshot](https://user-images.githubusercontent.com/57572400/125784167-618830ae-e475-4faf-81d3-194ad7ce3a08.png)](https://user-images.githubusercontent.com/57572400/125784167-618830ae-e475-4faf-81d3-194ad7ce3a08.png)

Additionally, autocompletion for element types provided by both Craft and plugins/modules is available, for example: `asset`, `entry`, `category`, `tag`, `user`, `product` (if Craft Commerce is installed), etc.

**N.B.:** If you are using a Docker-ized setup, ensure that `storage/runtime/compiled_classes/` is bind mounted on your client machine, so your IDE can find the classes to index them

Regenerating Autocomplete Classes
---------------------------------

[](#regenerating-autocomplete-classes)

The autocomplete classes are all generated any time Craft executes (whether via frontend request or via CLI), if they do not yet exist.

The autocomplete classes are all regenerated every time you install or uninstall a plugin.

If you manually add a plugin or module that registers variables on the Craft global variable, you can force the regeneratation of the autocomplete classes by running the following console command.

```
php craft autocomplete/regenerate
```

...or since the autocomplete classes are automatically regenerated if they don’t exist, you can clear the Runtime caches with:

```
php craft clear-caches/temp-files
```

Extending
---------

[](#extending)

You can extend the values that a `Generator` class adds using the `EVENT_BEFORE_GENERATE` event.

```
use nystudio107\autocomplete\events\DefineGeneratorValuesEvent;
use nystudio107\autocomplete\generators\AutocompleteTwigExtensionGenerator;
use yii\base\Event;

Event::on(AutocompleteTwigExtensionGenerator::class,
    AutocompleteTwigExtensionGenerator::EVENT_BEFORE_GENERATE,
    function(DefineGeneratorValuesEvent $event) {
        $event->values['myVariable'] = 'value';
    }
);
```

In addition to the provided autocomplete generator types, you can write your own by implementing the `GeneratorInterface` class or extending the abstract `Generator` class (recommended).

```
