有好些phpstorm使用者都知道它有live templates功能,但不知道怎么去定义或使用,详见,以下是从网上搜集来的资料,方便大家使用Live Templates,未做全文翻译。
Abbreviation Description
Template
Here are some of mine:
Forms
通过Live Template我们可以快速创建表单,使用模板可以节省更多时间。
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
其它模板分享:
<!--- $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>
.container>.col-md-10.col-md-offset-1>p.placeholder*6>lorem75
[tab]
结果:
<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>
当然你也可以通过以下方式来定义模板
.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]
parr
Print array enclosed with <pre>
tags
echo '<pre>'; print_r($array); echo '</pre>'
field
<!--- $VALUE$ Field ---> <div class="form-group $NAME$-field {{ $errors->has('$NAME$') ? ' has-error' : '' }}" id="$NAME$-field"> {!! Form::label('$NAME$', '$VALUE$:', ['class' => 'control-label']) !!} {!! Form::$TYPE$('$NAME$', null, ['class' => 'form-control']) !!} {!! $errors->first('$NAME$', '<p class="help-block error-msg">:message</p>') !!} </div>