Search code examples
phpstormlaravel-bladeintellij-13live-templates

In PHPStorm, while using Live Template, how can I replace underscore with a space?


I am using Live Templates in PHPStorm to easily create blocks of code using variables I define. I created a live template block that creates a group of elements for a text form field using the blade templating engine.

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

I set up the variables so that I can enter the NAME variable first in all lowercase letters, and it will then automatically fill in the VALUE variable for me while capitalizing the first letter.

enter image description here

Here's an example of how that works out when the name variable is a single word:

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

This works great, but I run into a problem when the field name has two words. I prefer to use underscores between two words for the NAME attribute, and unfortunately that underscore appears in the VALUE variable as well.

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

I can't find a expression in the live template variables setup that allows me to replace an underscore with a space. Ideally I would like to keep the first letter capitalized while also replacing any underscores with spaces for the VALUE variable. Any ideas how I can achieve this?


Solution

  • underscoresToSpaces(String) should do the thing. Like:

    capitalize(underscoresToSpaces(NAME))