Is it possible to use loops in IntelliJ live templates?

805 Views Asked by At

I noticed that IntelliJ has syntax for "set", "if" and "foreach" statements to build file templates.
http://www.jetbrains.com/idea/webhelp/file-and-code-templates.html. However, it doesn't seem like this is possible with live templates. Am I doing something wrong, or do they just not have this support?

Basically I'm looking for the same functionality as TextMate's snippets. It would be nice to create a script that would generate or transform text exactly how I want using tools like bash, perl, python or php (but I'd settle for #if and #foreach if that's possible too). And it looks like the IntelliJ TextMate plugin doesn't support this either, so is there any other plugin that would accomplish this?

2

There are 2 best solutions below

0
On

Yes, It is possible. Use groovyScript in variable. Example: groovyScript("def TABLE_NAME=\"${_1}\"; def resultStr=''; for(i = 1; i <= 99; i++) { resultStr+=\"\"\" \n CREATE TABLE ${TABLE_NAME}_${i} PARTITION OF ${TABLE_NAME} FOR VALUES IN (${i}); \"\"\"; }; return resultStr;", clipboard()) enter image description here

1
On

I figured out the answer to this. It looks like you can use Groovy scripts in live templates with the groovyScript("groovy code") predefined function