putyourlightson/craft-autocomplete

This package is abandoned and no longer maintained. The author suggests using the nystudio107/craft-autocomplete package instead.

Provides autocompletion for Craft and plugins in Twig templates.

1.0.1 2021-07-23 11:47 UTC

This package is auto-updated.

Last update: 2021-08-09 16:58:44 UTC


README

Stable Version Total Downloads

Autocomplete for Craft CMS [DEPRECATED]

⚠️ This package has been replaced by the superior Craft Autocomplete as a collaboration between PutYourLightsOn and nystudio107.

Provides autocompletion for Craft CMS and plugins in Twig templates.

Currently works with PhpStorm only, as VSCode does not support intellisense for Twig extensions.

Adapted from FauxTwigExtension.php by nystudio107 as documented in the article:
https://nystudio107.com/blog/auto-complete-craft-cms-3-apis-in-twig-with-phpstorm

demo

Usage

Install the package using composer.

composer require putyourlightson/craft-autocomplete

Ensure that the Symfony plugin is installed and enabled in PhpStorm:
https://plugins.jetbrains.com/plugin/7219-symfony-plugin

Once your IDE indexes the files, autocompletion for Craft and supported plugins will immediately become available in your Twig templates.

screenshot

Adding Custom Variables

You can add autocompletion for your own custom modules/plugins by creating a file called AutocompleteVariable.php and placing it inside any folder that PhpStorm will index (for example in the /config directory).

<?php

use craft\web\twig\variables\CraftVariable;
use my\plugin\variables\MyVariable;

/**
 * Adds variables to the global Craft Variable.
 *
 * @mixin MyVariable
 */
class AutocompleteVariable extends CraftVariable { }

Contributing

You can contribute autocompletion for third-party plugins that are available in the plugin store. To do so, copy the src/putyourlightson folder and rename it to your GitHub username. Modify the classes accordingly and add a @mixin for your variable to the main AutocompleteVariable class.

Ensure you follow the structure already in place, test that autocompletion works and submit a pull request.

screenshot-mixins

Created by PutYourLightsOn.