0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

phpstormでtwigをinclude時に補完させたい

Last updated at Posted at 2019-12-04

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>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?