spacer

PHPStorm File Templates Includes Custom Variables

by chance on Feb.10, 2012, under development, php, phpstorm, tools

PHPStorm's File template settings are very versatile. They allow you to not only make a file template, but also allow you to parse out redundant elements (such as licensing) in the template by allowing an includes section. In your File Template, any undefined variable automatically elicits a prompt from PHPStorm.

PHPStorm allows you access to the includes section via the #parse directive. If you're want To have Custom variables to be filled in correctly via prompt, you will need to have the variable declared in the template.

Example

"chance license.php"

/**
* @package ${Package}
* @author Chance Garcia
* @copyright (C)Copyright ${YEAR} chancegarcia.com
*/

In the above includes example, I'm wanting to have a custom variable named Package. I can only cause PHPStorm to prompt for this value if I include the variable in my template. If I'm already using the variable in the template, then it will fill in when the includes file is parsed.

Example:

<?php
#parse("chance license.php")
 
class ${Package}_#if(${ExtraClassInfo} != "")${ExtraClassInfo}_#end${NAME}
{
 
}

In the above template, the ${Package} variable will be given a prompt since it is used in the template and an unknown variable and the parsed "chance license.php" include will be able to use that prompt value.

I am also using another variable to Prompt for extra class name information. Since PHPStorm uses Velocity Template Language (VTL), I am able to use the VTL conditional syntax to insert that information if it is entered and ignore it if it is not. This technique is useful in a situation where you want your include file to have a custom variable value but do not need to display this value in your template.

Example:

<?xml version="1.0"?>
<!--
#if(${Package})#end
#parse("chance license.php")
-->

 

In the above example, we make PHPStorm prompt for the custom value needed for out parsed include file. This gives us our expected include file without printing our custom variable anywhere else in our template.

spacer

blog comments powered by Disqus
RSS feed for this post (comments) TrackBack URI

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Good reads

  • 37 Signals
  • Ben Ramsey
  • Chris Shiflett
  • Derick Rethans
  • Douglas Brown
  • Ed Finkler
  • Elizabeth Naramore
  • John Resig
  • Jose da Silva
  • Keith Casey
  • Lorna Jane
  • O’Reilly
  • Paul Jones
  • Pádraic Brady
  • Security Monkey
  • Stefan Esser
  • Terry Chay

Archives

All entries, chronologically...

  • February 2012
  • November 2011
  • October 2011
  • December 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • September 2009
  • August 2009
  • July 2009
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.