在 PhpStorm 的实时模板中使用数学 [英] Use math in PhpStorm's Live Template

查看:44
本文介绍了在 PhpStorm 的实时模板中使用数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 PhpStorm 的实时模板中使用数学?

例如,我的模板中有 $Image_width$ 并且想要设置像这样的高度图像:

解决方案

您可以使用 groovyScript() 函数来定义自定义表达式 - 请参阅

_1 这里是对作为参数传递给 groovyScript() 函数的第一个变量的引用

How can I use math in PhpStorm's Live Template?

For example, I have $Image_width$ in my template and want to set height image something like this:

<img width="$Image_width$" height="($Image_width$ / 2)">

解决方案

You can use groovyScript() function to define custom expressions - see https://www.jetbrains.com/help/phpstorm/template-variables.html#predefined_functions.

For example, for template like:

<img width="$Image_width$" height="$Image_width_half$">

you can specify groovyScript("def res=_1 as Integer; return res /2 ", Image_width) as expression for $Image_width_half$ variable:

_1 here is a reference to first variable passed as a parameter to groovyScript() function

这篇关于在 PhpStorm 的实时模板中使用数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆