EC-CUBE4を開発中にtwigファイルで補完されないから、どうやるんだろうと調べた。
以下の設定をすると呼び出し元に飛べたり、補完が出るようになる。
参考
https://symfony.com/doc/4.1/templating/namespaced_paths.html
twig.yamlに定義する
eccube_theme_front_default_dirに定義されているから
include'@~/Components'で補完はされるもののnamespaceがないと怒られてしまう。
今回は新しくThemeを定義した。
twig:
globals:
BaseInfo: null
eccube_config: '@Eccube\Common\EccubeConfig'
paths:
'%eccube_theme_front_dir%': ~
'%eccube_theme_front_default_dir%': ~
'%kernel.project_dir%/app/Plugin': ~
'%eccube_theme_admin_dir%': admin
'%eccube_theme_admin_default_dir%': admin
'%eccube_theme_user_data_dir%': user_data
'%eccube_theme_src_dir%/toolbar': toolbar
'%eccube_theme_src_dir%/common': common
'%kernel.project_dir%/app/template/default': Theme //追加
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
form_themes: ['bootstrap_4_layout.html.twig']
phpstormの設定
Preferences | Languages & Frameworks | PHP | Symfony | Twig / TemplateからThemeで設定したディレクトリを設定する。
定義した値に@つけてあげればphpstorm側で補完してくれる。
これで開発が捗るね!
{# 商品名 #}
<div class="ec-productRole__title">
{{ include('@Theme/Components/ProductDetail/Profile/productName.twig') }}
</div>