{"id":20715,"date":"2018-07-23T12:44:01","date_gmt":"2018-07-23T12:44:01","guid":{"rendered":"https:\/\/blog.jetbrains.com\/phpstorm\/?p=13048"},"modified":"2024-01-09T14:51:43","modified_gmt":"2024-01-09T13:51:43","slug":"custom-postfix-completion-templates","status":"publish","type":"phpstorm","link":"https:\/\/blog.jetbrains.com\/phpstorm\/2018\/07\/custom-postfix-completion-templates\/","title":{"rendered":"Custom postfix completion templates"},"content":{"rendered":"<p>Postfix code completion is a handy feature that lets you transform an existing expression into a different one, based on a postfix you specify after the dot.<\/p>\n<p>For example, to iterate over an object, use the <span class=\"lang:default highlight:0 decode:true crayon-inline \">fe<\/span>\u00a0 postfix after your expression:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/07\/phpstorm-general_postfix_thumbnail_edited.png\" alt=\"Postfix template\" width=\"572\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/07\/phpstorm-general_postfix_edited.gif\" \/><\/p>\n<p>Postfix completion has existed in PhpStorm since version 9, but has only provided a limited number of predefined templates. In PhpStorm 2018.2, you can create postfix completion templates yourself, tailoring them for your project and your coding style.<\/p>\n<p><!--more--><\/p>\n<p>To start creating a new postfix template, navigate to <em>Preferences | Editor | General | Postfix Completion<\/em>, click <em>+<\/em> , and select <em>PHP<\/em>:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-13050\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/07\/phpstorm-create_postfix_template_1.png\" alt=\"create_postfix_template_1\" width=\"800\" height=\"469\" \/><\/p>\n<p>Inside your template, use the <em>$EXPR$<\/em> and the <em>$END$<\/em> variables. The former will capture the expression before\u00a0the dot, while the latter will define the position of the caret after the template is expanded:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-13053 alignnone\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/07\/phpstorm-create_postfix_template_2.png\" alt=\"create_postfix_template_2\" width=\"405\" height=\"348\" \/><\/p>\n<p>Let&#8217;s apply the created template:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/07\/phpstorm-apply_custom_postfix_thumbnail_edited.png\" alt=\"Postfix template\" width=\"572\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2018\/07\/phpstorm-apply_custom_postfix_edited.gif\" \/><\/p>\n<p>As you can see, PhpStorm has detected two expressions that are applicable for the template, so it has prompted us to choose one. If you need to always apply your template to the entire expression without selecting the scope for it every time, enable the <em>Apply to the topmost expression<\/em> option when creating a template. This way, the topmost applicable expression will be selected automatically.<\/p>\n<p>Please look at the\u00a0<strong><a href=\"https:\/\/www.jetbrains.com\/phpstorm\/nextversion\/\" target=\"_blank\" rel=\"noopener\">overview of all PhpStorm 2018.2 features<\/a><\/strong>\u00a0and\u00a0<a href=\"https:\/\/www.jetbrains.com\/phpstorm\/nextversion\/\" target=\"_blank\" rel=\"noopener\">download<\/a>\u00a0the Public Preview build from the PhpStorm website.<\/p>\n<p>If you have any feedback to share with us, please\u00a0leave your comments to this blog post or in our public\u00a0<a href=\"http:\/\/youtrack.jetbrains.com\/issues\/WI\" target=\"_blank\" rel=\"noopener\">issue tracker<\/a>. Stay tuned\u00a0as the PhpStorm 2018.2 release is just around the corner!<\/p>\n<p><em>Your JetBrains PhpStorm Team<\/em><br \/>\n<em>The Drive to Develop<\/em><\/p>\n","protected":false},"author":745,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","categories":[808,907],"tags":[227,602,743,91],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/20715"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/types\/phpstorm"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/users\/745"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/comments?post=20715"}],"version-history":[{"count":1,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/20715\/revisions"}],"predecessor-version":[{"id":431968,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/phpstorm\/20715\/revisions\/431968"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media?parent=20715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/categories?post=20715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/tags?post=20715"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/cross-post-tag?post=20715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}