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

BenSmith's avatar

Share Your PHPStorm Live Templates

One of the biggest improvements to my workflow over the last few months has been to create a live template for anything I find myself doing more than twice a day.

This new sub forum seems like a good place to share these templates and I would love to see any you have created and are particularly fond of.

Rather than just exporting all your templates into a file, I think it is probably better to just include them in a post with the following format:

Abbreviation Description

Template

Here are some of mine:

Forms

Seeing Jeffrey using variations of these to quickly create forms was what first made me realise how much time could be saved using templates. These are integrated to work well with the Twitter Bootstrap framework.

fo Form open tag

{!! Form::open() !!}

fc Form close tag

{!! Form::close() !!}

textfield Text form field

<!--- $VALUE$ Field --->
<div class="form-group">
    {!! Form::label('$NAME$', '$VALUE$:') !!}
    {!! Form::text('$NAME$', null, ['class' => 'form-control']) !!}
</div>

emailfield Email form field

<!--- $VALUE$ Field --->
<div class="form-group">
    {!! Form::label('$NAME$', '$VALUE$:') !!}
    {!! Form::email('$NAME$', null, ['class' => 'form-control']) !!}
</div>

passwordfield Password form field

<!--- $VALUE$ Field --->
<div class="form-group">
    {!! Form::label('$NAME$', '$VALUE$:') !!}
    {!! Form::password('$NAME$', ['class' => 'form-control']) !!}
</div>

textareafield Text area form field

<!--- $VALUE$ Field --->
<div class="form-group">
    {!! Form::label('$NAME$', '$VALUE$:') !!}
    {!! Form::textarea('$NAME$', null, ['class' => 'form-control']) !!}
</div>

hiddenfield Hidden form field

{!! Form::hidden('$NAME$', $VALUE$) !!}

submitfield Submit form field

<!--- $VALUE$ Field --->
<div class="form-group">
    {!! Form::submit('$NAME$', ['class' => 'btn btn-primary']) !!}
</div>

req Require field (add in the attribute array of any form field type to make field required.

'required' => 'required'

Annotations

I've been playing with 5.0 for a few weeks now and so I've added a few route annotation templates. I'm sure more will be added over the coming months.

anno Add docblock ready for annotations below

/**
* $ANNOTATIONS$
* @return Response
*/

@G Get route annotation

@Get("$ROUTE$", as="$NAME$")

@P Post route annotation

@Post("$ROUTE$", as="$NAME$")

@M Get route annotation

@Middleware("$NAME$")

Blade Live Templates

I’ve been using these less since native blade support was added to PHPStorm but they are still useful.

@ex Blade extend

@extends('$VIEW$')

@fe Blade foreach

@foreach($GROUP$ as $INDIVIDUAL$)
    $ACTION$
@endforeach

@if Blade if

@if($BOOLEAN$)
    $OPERATION$
@endif

@ife Blade if/else

@if($BOOLEAN$)
    $OPERATION$
@else

@endif

@inc Blade include

@include('$INCLUDE$')

@sect Blade section

@section('$SECTION$')
    $CONTENT$
@stop

@yi Blade yield

@yield('$YIELD$')

bb {{ }} unescaped blade tags

{{ $CODE$ }}

bbb {!! !!} escaped blade tags

{!! $CODE$ !!}

view New view from layout

@extends('$LAYOUT$')

@section('content')
    $CONTENT$
@stop

Testing

A few testing templates, I’m only just getting properly into test so I will be adding to these.

cci Codeception $I->

$I->$FUNCTION$

@test Test outline

/** @test */
public function it_$METHOD$()
{
    // Given
        $GIVEN$
    // When
        $WHEN$
    // Then
        $THEN$
 }

HTML

I use these when I'm working on a throw away project and need to quickly import some basic styles and scripts.

bootcss Bootstrap css CDN link

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>

bootjs Bootstrap js CDN link

<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

jquery jQuery CDN link

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

lorem lorem ipsum generator

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Composer packages

I have a few packages that I add to every laravel install I do. Rather than have to remember the correct package number I just create a template to insert it into my composer file automatically (note: these are for Laravel 5).

gener Way/Generators

"way/generators": "~3.0",

illhtml Illuminate/Html

"illuminate/html": "~5.0",

reqdev Add require-dev to composer.json file

"require-dev": {
    $DEPENDENCY$
},

Misc

A few more that don’t quite fit into any category

lt Link to

{!! link_to('$PATH$', '$TEXT$') !!}

ltr Link to route

{!! link_to_route('$ROUTE$', '$TEXT$') !!}

errors Error loop

@if($errors->any())
    <ul>
@foreach($errors->all() as $error)
    <li>{{ $error }}</li>
@endforeach
    </ul>
@endif

I have loads more but it's quite tiresome writing them, I'll add more a bit later today!

0 likes
51 replies
austenc's avatar

Thanks @BenSmith.

Trying out PHPstorm now coming from sublime text and I feel like I'm not utilizing a lot of the features that truly make it awesome like this.

domioanna's avatar

Awesome work. May be adding these to my PHPStorm

unitedworx's avatar

wow! this looks like i need to start using phpstorm live templates :)

Erik's avatar

This are some very helpful snippets. Thanks a lot.

1 like
Jeffberry's avatar

@Smally, you need to upgrade to PHPStorm 8.0.2 and then go into your preferences menu (either just search for "Blade" or go to Languages & Frameworks -> PHP -> Blade) and there you can change the different tags that the IDE recognizes.

SNaRe's avatar

Annotations are not default anymore. Rather than annotation can you create template for routes?

DirkZz's avatar

About the lorem template, not sure if you are aware of this, but this is actually set by default in PHPStorm.

lorem5[tab] for example will generate "Lorem ipsum dolor sit amet."

Where you can replace 5 with the amount of words you like.

1 like
mrebstock's avatar

anyone able to share their live templates as xml? All the ones listed by @BenSmith would be very helpful, but definitely requires some commitment to create them all.

nbj's avatar

While watching lessons, I have noticed that @JeffreyWay often uses live templates for adding a <div> with a specific class simply by typing .<className> and hitting tab. That is a rather nice live template, but I can't quite figure out how to make it work, making all live template variations seems like tedious work, so there must something I have overlooked.

davorminchorov's avatar

Emmet comes with PHPStorm 8 (and maybe older versions too) by default.

neovive's avatar

@austenc Browse through the Be Awesome in PHPStorm series on laracasts, if you haven't done so already. One of things I like about PHPStorm is that many of the things you need are already built-in out of the box: Emmet, Namespace importing, generators. It's so configurable, to the point of being overwhelming, but a quick Google search yields many automation tips when you need them.

nbj's avatar

Thx guys :)

I had been looking for this feature in the live template section, so Emmet put me back on track.

gdespirito's avatar

I also use another field template

field You can change the type, but by default it will be text. (edit variables)

<!--- $VALUE$ Field --->
<div class="form-group $NAME$-field" id="$NAME$-field">
    {!! Form::label('$NAME$', '$VALUE$:') !!}
    {!! Form::$TYPE$('$NAME$', null, ['class' => 'form-control']) !!}
    {!! $errors->first('$NAME$', '<p class="help-block error-msg">:message</p>') !!}
</div>

willvincent's avatar

Anyone who's never used it before, you should check out the Emmet docs

It can be a HUGE time saver..

Suppose you want to generate half a dozen paragraphs of placeholder text in a div with a specific id and a few classes, and while we're at it wrap that in a container div...

.container>.col-md-10.col-md-offset-1>p.placeholder*6>lorem75 [tab]

Results in:

<div class="container">
  <div class="col-md-10 col-md-offset-1">
    <p class="placeholder">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad aut blanditiis debitis dicta est
     inventore, labore? At atque corporis deleniti dolor dolore ducimus, eos eum hic, incidunt
     ipsa ipsum nisi numquam officiis quo rem sequi sint veritatis? Aperiam, odio quasi. Aliquid
     dolorum hic labore nulla odit quasi quod, voluptatum! Alias animi architecto beatae deleniti,
     eligendi inventore modi possimus quam saepe tempore totam velit. Assumenda delectus
     exercitationem expedita fugiat magni maiores nam quibusdam quo sed soluta?</p>

    <p class="placeholder">Ad consectetur debitis dicta dolorem dolorum earum eligendi enim eos et, eum facere fugiat
      hic id incidunt inventore iusto laboriosam laudantium maxime nemo nihil placeat possimus
      quae, quibusdam ratione recusandae, reiciendis sapiente sequi tempora tempore tenetur ullam
      veritatis voluptates voluptatibus. Accusantium alias assumenda aut cum cupiditate dolor
      dolorem esse eum illo ipsa iste itaque laboriosam molestiae nemo omnis possimus, quaerat
      repellendus sapiente, sint sit sunt temporibus totam vero vitae voluptatibus. Aliquam neque
      placeat quasi velit!</p>

    <p class="placeholder">Ab at atque corporis deleniti dicta dignissimos, explicabo fugit illum in ipsam labore modi
     nam necessitatibus nostrum numquam perferendis quae quos ratione repellendus suscipit.
     Adipisci alias consequuntur dolorem, doloribus eaque eligendi enim eos est excepturi
     exercitationem harum nulla numquam odio, odit porro possimus quasi recusandae reprehenderit,
     sed velit. Aliquid animi est facere impedit, ipsam minus nobis numquam porro quia
     reprehenderit sed sequi soluta voluptates. Accusantium aliquam error excepturi exercitationem
     labore magnam nobis porro vero, voluptas?</p>

    <p class="placeholder">A at cum dolor eum fuga harum laudantium modi mollitia, nostrum quos sit suscipit tempora ut
     vero voluptatem. Cum dignissimos doloremque eaque, esse est, eum fugiat obcaecati, omnis
     perferendis placeat quae similique sunt! Adipisci aliquid culpa eum harum magni nesciunt
     numquam optio quo soluta vel? Aliquam aspernatur deleniti, eaque expedita facilis modi nam
     praesentium reiciendis sequi! Alias aspernatur autem debitis delectus exercitationem illum
     incidunt iusto libero minima, molestias mollitia obcaecati, odio officiis pariatur suscipit
     voluptatum?</p>

    <p class="placeholder">Aliquam dignissimos enim est excepturi exercitationem iure laudantium nam non obcaecati
     officiis provident, quam ratione velit. Accusantium amet architecto, aspernatur commodi
     cumque cupiditate dicta dolore earum facere id ipsa laborum magni maxime modi molestias natus
     neque nisi nostrum numquam omnis optio placeat quibusdam quidem recusandae similique
     temporibus totam veniam veritatis voluptatem voluptatum. Cumque dolores mollitia unde.
     Aperiam aut dignissimos, hic inventore ipsum nam nemo odit quis repellat saepe sed sit
     suscipit vero! Ducimus ratione, sit!</p>

    <p class="placeholder">Atque autem consectetur, dolor doloribus ducimus est expedita itaque laudantium minus nam,
     necessitatibus quae quia voluptatem. Animi ducimus eaque iusto nobis possimus sequi velit. A
     adipisci aliquid blanditiis eligendi error exercitationem ipsam laboriosam, molestiae
     molestias neque nostrum numquam obcaecati officia officiis quaerat quia quos sed tenetur unde
     ut! Corporis delectus doloremque doloribus ea eum, eveniet hic illum in ipsa iure iusto
     labore laborum laudantium maiores nesciunt odit officia optio porro quam quis sint tenetur
     voluptates.</p>
  </div>
</div>

Of course, you can omit the 75 at the end of that string, and it'll generate 30 word paragraphs, but those can look a bit short.

Suppose you want two columns of placeholder text, no problem with emmet:

.container>.row>.col-md-6*2>p*2>lorem [tab]

Or, two columns, followed by 3 columns:

.row>(.col-md-6*2>p*2>lorem)+.row>.col-md-4*3>p>lorem [tab]

Finally, three columns, followed by 2, then followed by 4:

.row>(.col-md-4*3>p>lorem)+.row>(.col-md-6*2>p*2>lorem)+.row>.col-md-3*4>p>lorem [tab]

Beyond that, it's probably best to not try to squeeze it all into a single string.. lol

GhazanfarMir's avatar

One of my favourite is

parr Print array enclosed with <pre> tags

echo '<pre>';
print_r($array);
echo '</pre>'
ovvessem's avatar

Thanks for sharing @BenSmith. Question related to Live Templates in combination with Emmet. Which keystroke do you use to expand the Emmet abbreviation since TAB is needed for some Live Templates with variables.

Next

Please or to participate in this conversation.