Here's How to Fix Multi-File Templates in PhpStorm

Опубликовано: 17 Июль 2026
на канале: weph
87
5

Using PhpStorm's file templates can streamline your development process and reduce the amount of boilerplate code you need to write. Did you know that you can also use them to create multiple files at once? This feature is great, but it has a limitation: you can't use namespaces. More specifically, the predefined variable holding the current namespace is missing. This used to be a general problem with the file templates, but JetBrains provided a fix for single-file templates. However, this solution doesn’t work for multi-file templates. In this video, I'll show you a workaround that allows you to use this feature despite the limitation.

More productivity tips:    • Developer Productivity  

Chapters

00:00 Intro
00:41 Quick Demonstration
01:51 The Basics
03:04 The Problem
07:03 The Solution
08:56 Outro

Code Snippet

Here's the code snippet that I refer to in this video:

#set($NAMESPACE_PREFIX = $PROJECT_NAME.substring($PROJECT_NAME.indexOf("(") + 1, $PROJECT_NAME.indexOf(")")))
#set($DIR_WITH_NAMESPACE_PREFIX = $DIR_PATH.concat("/").replace('src/', "${NAMESPACE_PREFIX}/"))
#set($NAMESPACE = $DIR_WITH_NAMESPACE_PREFIX.replace('/', '\').substring(0, $DIR_WITH_NAMESPACE_PREFIX.length() - 1))

#JetBrains #PhpStorm #php #developertips #CodingTips #PHPDevelopment #DeveloperTools #DeveloperLife