Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file name while creating snippets (Live Templates)

Tags:

webstorm

I am creating a snippet for my templates in Meteor and the only thing left to be perfect would be to know the file name in which that snippet was called.

What I have:

type: temp + tab

What I get:

 <template name="">

 </template>

What I want:

 <template name="">
   file_name.html
 </template>
like image 367
Cassio Cabral Avatar asked Dec 05 '25 19:12

Cassio Cabral


1 Answers

Live Templates is how "snippets" are called in WebStorm and other IDEA-based IDEs.

There is filename() function (fileNameWithoutExtension() has been added a few version later) that can provide such info/text for a variable. Official documentation.

Knowing that: add a variable into your template and then use the aforementioned function on it:

<template name="$END$">
    $FILE$
</template>

Now click on "Edit Variables" button and use it there. Selecting "Skip if defined" will make that variable "non-editable" during template expansion.

enter image description here

like image 132
LazyOne Avatar answered Dec 08 '25 21:12

LazyOne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!