jahvi / magento2-copy-theme-override
Magento 2 command to automatically copy files into active theme
Installs: 4 525
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 1
Forks: 3
Open Issues: 0
Type:magento2-module
pkg:composer/jahvi/magento2-copy-theme-override
Requires
- php: ^7.3
- magento/framework: ^102|^103
- symfony/console: ^4.1
Requires (Dev)
README
🎩 Magento 2 command to automatically copy files into active theme.
Installation
- Install via composer
composer require jahvi/magento2-copy-theme-override --dev - Run
php bin/magento setup:upgrade
How it works?
After installing the extension you will have access to a new command:
php bin/magento dev:copy-theme-override $file_path
This takes a single $file_path argument which is the absolute path of the CSS, LESS, JS, PHTML or HTML file you want to override in your theme, so for example to override the product/list.phtml template you'd run:
php bin/magento dev:copy-theme-override /var/www/magento2/vendor/magento/module-catalog/view/frontend/templates/product/list.phtml
And it will copy the file into your theme as:
/var/www/magento2/vendor/magento/app/design/Sample/theme/Magento_Catalog/templates/product/list.phtml
Setting up your IDE
By itself the command is not very useful but most IDEs or code editors provide a way to run custom commands using keyboard shortcuts that will help simplify this workflow, below are some examples of a few popular ones.
VS Code
- Create a
.vscode/tasks.jsonfile in the project root with the following content:
{
"version": "2.0.0",
"tasks": [
{
"label": "Copy Theme Override",
"type": "shell",
"command": "php bin/magento dev:copy-theme-override ${file}",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- Open the file to override.
- Run build task shortcut, by default
Shift + Cmd + BorCtrl + Shift + Bon Windows/Linux.
Sublime Text
- Create new build system
Tools > Build System > New Build System...with the following content:
{
"shell_cmd": "php bin/magento dev:copy-theme-override $file",
"working_dir": "$folder"
}
- Open the file to override.
- Run Build task, by default
Cmd + BorCtrl + Bon Windows/Linux.
