Search code examples
phpstormwebstorm

How to say to PhpStorm/WebStorm where the including file resides?


Any web project consists of lots of partials that are included into the main file. Very often IDE (PhpStorm for my case) doesn’t know where the including partial resides. The thing is sometimes we use absolute path (e.g. in AngularJS to specify where views’ or directive’s templates reside) and relative path in preprocessors’ sources (jade, stylus, coffee, etc.). And all these files can be stored somewhere in the folder structure.

Therefore very often you can’t to open the including file right from the main file using Ctrl+B.

I think there is a way to tell IDE where this file actually resides. Does anybody know how to cope with it? If there is no way, I suppose we should ask the developer to solve it somehow.


Solution

  • Depending on the particular framework in which you're developing, a PhpStorm plugin might exist to make CTRL+B navigation possible. For instance, using the Symfony plugin (installed via Settings > Plugins), CTRL+B navigation into a partial template becomes possible in code like this: return $this->render('hello/world/index.html.twig');

    If a plugin is not available, try the following steps. It's not a perfect solution, but it's better than nothing! It's also extremely quick once you get the hang of it.

    1. With your cursor inside the string containing the path and filename, use the 'Extend Selection' keyboard shortcut until the entire string is highlighted (excluding any wrapping single/double quotes). If you don't currently have the 'Extend Selection' action mapped, you can do so via Settings > Keymap.
    2. Immediately use the 'Navigate to File' shortcut (CTRL+SHIFT+N) to search for all files matching the path/filename contained in the string you previously highlighted.
    3. A dropdown box will appear containing all matching files. Find the proper one and open it using ENTER.