【问题标题】:In PHPStorm, while using Live Template, how can I replace underscore with a space?在 PHPStorm 中,使用 Live Template 时,如何用空格替换下划线?
【发布时间】:2015-04-06 09:33:26
【问题描述】:

我在 PHPStorm 中使用 Live Templates 来使用我定义的变量轻松创建代码块。我创建了一个实时模板块,它使用刀片模板引擎为文本表单字段创建一组元素。

<!--- $VALUE$ Field --->
<div class="form-group">
    {{ Form::label('$NAME$', '$VALUE$') }}
    {{ Form::text('$NAME$', null, []) }}
</div>

我设置了变量,这样我就可以先输入所有小写字母的NAME变量,然后它会在第一个字母大写的同时自动为我填写VALUE变量。

下面是一个例子,说明当 name 变量是一个单词时如何解决这个问题:

<!--- Address Field --->
<div class="form-group">
    {{ Form::label('address', 'Address') }}
    {{ Form::text('address', null, []) }}
</div>

这很好用,但是当字段名称有两个单词时我遇到了问题。我更喜欢在 NAME 属性的两个单词之间使用下划线,不幸的是,下划线也出现在 VALUE 变量中。

<!--- Zip_code Field --->
<div class="form-group">
    {{ Form::label('zip_code', 'Zip_code') }}
    {{ Form::text('zip_code', null, []) }}
</div>

我在实时模板变量设置中找不到允许我用空格替换下划线的表达式。理想情况下,我希望将第一个字母保持大写,同时将任何下划线替换为 VALUE 变量的空格。有什么想法可以实现吗?

【问题讨论】:

    标签: phpstorm blade intellij-13 live-templates


    【解决方案1】:

    underscoresToSpaces(String) 应该这样做。喜欢:

    capitalize(underscoresToSpaces(NAME))
    

    【讨论】:

    • 太完美了!谢谢!
    猜你喜欢
    • 2010-11-03
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多