Phpstorm Live template plus php short syntax-Open tags to create native templates

Source: Internet
Author: User

About PHP should not use the template has been discussed, supported by the use of templates more concise, easy to communicate with the front-end project division. The objection is that PHP itself supports inline syntax, and it is not necessary to use a template to reduce performance.

In fact, using PHP's phrase method. Direct embedding is also not very ugly, the support of the loop what support, and then with the Phpstorm artifact of the live Template, even shift does not have to press, very convenient. (Other Ides should also have the corresponding Code snippet feature)

First look at the effect:

output [Stv]<?

= $x? >//if-else [Stif]<? if ($x > $y):?

>

>

><?

foreach ($list as $val): >a=<?= $val? ><? Endforeach >//foreach key=>value [stforek]<? foreach (Array (' A ' =>1, ' B ' + 2) as $key = $var): ><?= $ $key? >=><?= $var?

><? Endforeach?

>//while [Stw]<? while ($i <):?>

Switch is not a branch, but a PHP block, because it has to be followed by a break. Just because the if-else in the phrase method is also very intuitive, can replace switch. I also specially added &lt in the Phpstorm;? ElseIf ($x = = 1):?> Fragment for easy addition of inference logic.


The prerequisite is to open support in php.ini, Short_open_tag = on. Also supported in the SAE. Other cloud sites have not yet been tried.

Other than that. PHP5.4 after, do not set short_open_tag=on,<?=?> is always available, (but <?

?> still need to set php.ini to open). It shows that there is a lot of demand for it. Really worry about compatibility can manually change the live template, will <?> change to <?php?

>.


The following is the addition of the live template in Phpstrom, which is equivalent to the syntax hint, you enter the first few letters (keyword). Press TAB. It is on its own initiative to the definition of the complement.

Keyword I wrote them in brackets in the code above.

Phpstorm configuration I do not have to paste, the back of the need, the following is a demo example of while [STW]:

<? while ($$ $VAR $ $COND $ $COMP $):?> $END $<? $$ $VAR $++?> <? Endwhile?

>


Setting.jar: Setting.jar (which contains only the live template settings.) And put it in a self-built folder. Don't worry about overwriting your own settings.

Phpstorm Live template plus php short syntax-Open tags to create native templates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.