Sharing Code Snippets in PhpStorm Easy Way
Code snippets, or Live Templates as they are called in PhpStorm, can help you save and reuse code. This can be any code fragment that you find yourself using often – just a single line of code like a method definition, or a hundred lines skeleton for a whole feature.
Many code snippets, such as Project-specific snippets, Framework snippets, or Library snippets, can be useful for your team and even the entire community. PhpStorm allows you to share snippets via GitHub repositories!
Some of our users already shared code snippets and provided instructions on how to install them by copying files manually. But there is a much simpler way to obtain shared snippets: You can do it by adding a read-only settings repository:
- Go to Preferences (Settings) | Tools | Settings Repository
- Add a read-only source with a link to GitHub repository
- Restart PhpStorm
In fact, this way you can share not only live templates, but other IDE settings too. Read more about all shareable parts here. The settings repository that you plan to share must contain the templates folder with Live Templates XML files inside:
/ ├── templates/ │ ├── template_set_1.xml │ ├── template_set_2.xml │ ├── ... │ └── template_set_N.xml └── ...
Check out a few ready-to-use repos with snippets:
- Laravel koomai/phpstorm-laravel-live-templates (⭐️964)
- Symfony, Twig knpuniversity/phpstorm-settings (⭐️123)
- WordPress gist://pronskiy/e0463181ed5bf1f08cdcccb32af87dc6 (fork ⭐️54)
- Twig pronskiy/PhpStorm-Live-Templates-Twig-Extended (fork ⭐️20)
- Magento phpstorm-magento-live-templates (⭐️4)
Share your live templates and send us a link!
We are brainstorming on how to improve the sharing experience. For example, maybe distribute live templates as Composer packages? We’d appreciate any comments and suggestions!
Please let us know what you think of this approach. Do you use live templates? What are they lacking to be perfect for you?