PhpStorm 2016.3 Help

Using Blade Templates

In this section:


PhpStorm provides full support of the Laravel Blade template engine up to version 5.1. This support involves:

  • Highlighting of Blade syntax in template files.
  • Code completion for all Blade directives, both predefined and custom, as well as for braces.
  • In @for and @foreach directives, variable introduction is offered with autocompletion inside the code constructs.
  • Expanding and folding sections defined through the @section directive. A block of code between a @section directive and a closing directive (for example, @stop) can be expanded or folded by clicking /help/img/idea/2016.3/foldingPlus.gif or /help/img/idea/2016.3/foldingMinus.gif in the gutter area.
  • Dedicated Blade-specific code inspections, for example an inspection to check that a section opened with @section directive is closed with one of the corresponding directives.
  • Blade-aware navigation with Ctrl+B includes links to templates in @extends and @include directives.
  • Finding usages (Alt+F7) can be invoked on a file name or a symbol in the code to show all the usages of a template across your codebase. Currently this functionality is available only inside other templates, but not from views.
  • Customizing predefined Blade directives and defining custom directives for Blade templates.

Preparing to use Blade templates

Before you start, make sure the PHP and Blade plugins are installed and enabled. The plugins are bundled with PhpStorm and activated by default. If the plugins are not activated, enable them on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.

Adding, editing, and removing Blade directives

In PhpStorm, Blade directives are managed in the Directives tab of the Blade Page. The tab lists all the currently available Blade directives, for those that have parameters, the prefixes and suffixes are also shown. When you start, the list contains only predefined directives. You can edit these directives as well as create custom ones.

  1. Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing File | Settings for Windows and Linux or PhpStorm | Preferences for OS X. Expand the Languages&Frameworks node, and then click Blade under PHP. On the Blade page that opens, switch to the Directives tab. The tab shows a list of all currently available directives.
  2. Do one of the following:
    • To define a new directive, click the Add directive button /help/img/idea/2016.3/new.png and then specify the directive's name in the Name text box. If the new directives requires a prefix and a suffix, select the Has parameter check box and type the prefix and suffix to use in the Prefix and Suffix text boxes respectively. PhpStorm will automatically enclose the prefix and suffix in opening and closing brackets and quotes and add a colon separator : so the parameters will look as follows: ("<prefix>:<suffix>").
    • To edit an existing directive, select it in the list and change the values in the text boxes below. To restore the original definition, click the Reset to defaults button /help/img/idea/2016.3/icon_resetToDefault.png.
    • To remove a directive from the list, select it and click the Remove directive button /help/img/idea/2016.3/delete.png.

Configuring Blade delimiters

PhpStorm recognizes Blade templates and provides error highlighting and code completion for them based on the delimiters you specify. These delimiters are managed in the Text Tags tab of the Blade Page.

The fields in the tab show the opening and closing characters for raw tags, content tags, and escaped tags.

The fields are filled in with the default values in compliance with Blade Templates 5.1. If you are using an earlier version, you can specify the relevant custom delimiters and PhpStorm will provide coding assistance according to the new rules.

See Also


Last modified: 23 March 2017