Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gitwithravish's avatar

PHPStorm - File Templates

How can I make something like this?

<?php

#if (${NAMESPACE})
namespace ${NAMESPACE};
#else
namespace App\Http\Controllers;
#end

use Illuminate\Http\Request;

class ${NAME} extends Controller { 
    
}

When no namespace is given, I want to add a default namespace.

0 likes
4 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

It would be easy to do with a live template

Add it like this

<?php

namespace $NAMESPACE$;

use Illuminate\Http\Request;

class $NAME$ extends Controller { 
    
}

Now click "Edit variables" and put App\Http\Controllersinto the default value of $NAMESPACE$

http://i.imgur.com/fyiu6Cu.png

gitwithravish's avatar

@sinnbeck Thank you ! I want to use phpstorm settings that jeffrey way uses. It looks minimal and cleaner. Any source where I can find it !?

Sinnbeck's avatar

Ive added both an answer for live templates and file templates. In the file template I put a link to the syntax.

You can always just google the name of the setting (for instance "File and code templates phpstorm") and you will most likely get a hit with the official docs

1 like

Please or to participate in this conversation.