[TxMt] templates: multiple files

Allan Odgaard throw-away-1 at macromates.com
Fri Feb 17 15:41:53 UTC 2006


On 16/2/2006, at 3:38, Quinn Comendant wrote:

> I notice that you can define multiple files for a template, but I  
> can't
> figure out how to create multiple files when running the template. Why
> else would TM use multiple files in a template? But then again, there
> seems to be only one $TM_NEW_FILE variable per template.

This part got lost when the bundle editor was extended to allow  
editing of templates. But with a little will, it is possible.

The creation of the template file(s) is done entirely by the little  
shell script, which each template has.

Take a look at the Objective-C -> Singleton template, which creates  
both the source and the header.

But for TextMate to know that the template creates more than one file  
(this is only so that all the files gets added to the project, after  
creation), the “info.plist” property list file which store the  
template info needs to have a “files” key where the value is a shell  
command that returns the path to each new file generated.

Again I refer to the info.plist of the Objective-C singleton template  
[1].

It is necessary to manually edit the info.plist on-disk to add the  
key/value pair, and TextMate needs to be relaunched afterwards.

I forgot to mention it in the Future Directions blog post, but  
templates is another part I also plan to revise in 2.0. Instead a  
template will just be instantiation of a snippet in a new document,  
and there will (likely) be some means to have multiple documents crated.

> A quick side question, how can I populate env variables at runtime? If
> my template has ${WHAT_DID_I_HAVE_FOR_LUNCH_TODAY} and I want to run a
> template every day... is it possible to popup a dialog with fields to
> fill-in or something?

You can't have placeholders in templates, as you can with snippets,  
i.e. where the caret is taken to each placeholder in turn. But you  
can insert the value of an environment variable in the template, as  
the template file is generated by a shell command, you could in  
practice write your templates as php or erb files, and let that  
command just pipe the template through php or erb and into $TM_NEW_FILE.



[1] http://anon:anon@macromates.com/svn/Bundles/trunk/Bundles/ 
Objective-C.tmbundle/Templates/Singleton/info.plist




More information about the textmate mailing list