Sublime Forum

File Templates

#1

Hey,

i’ve just finished my first Version of SublimeFileTemplates.
Basically it enables you to create Files with Snippet Content in one swoop.

Check out the GitHub Page or this Video to learn more:

github.com/mneuhaus/SublimeFileTemplates

http://www.youtube.com/watch?v=M4isYen7_Z4)

0 Likes

How can I insert comments too for PEAR standard in PHP?
#2

Now available through Package Control :smile:

0 Likes

#3

I saw this the other day.

I wondered why not just bind ctrl+n a show_quick_panel command that lists and executes new template commands.
When you select the

For example: new_templates.py

class NewHtmlCommand(sublime_plugin.WindowCommand):
    def run(self):
        v = self.window.new_file()
        v.settings().set('default_extension', 'html')
        v.set_syntax_file('Packages/HTML/HTML.tmLanguage')
        template = """<!doctype html>
<html>
<head>
    <title>$1</title>
</head>
<body>
$0
</body>
</html>"""
        v.run_command("insert_snippet", {"contents": template})

class NewMarkdownCommand(sublime_plugin.WindowCommand):
    def run(self):
        v = self.window.new_file()
        v.settings().set('default_extension', 'md')
        v.set_syntax_file('Packages/Markdown/Markdown.tmLanguage')
        template = """---
layout: $1
title: $2
---
#$2
$0
"""
        v.run_command("insert_snippet", {"contents": template})
0 Likes

#4

My Plugin does a few more things:

you can predefine the filename based on a specific need. For example, if you Controllers all have be named MyController.php you can define an argument to enter the controller’s name and then use this argument in the filename: “$nameController.php” and then you can use this argument inside the template as well.
Additionally you can specify a predefined path for files. In case of the example above you could pre-define the path to be “Classes/Controllers/”. So this file will be easily created inside that Folder by default.

i guess you could do all that inside your own custom commands, but my package bundles this behavior neatly into a plugin so anyone can just create some file-templates inside their packages.

greetings marc

0 Likes

#5

HI, I’ll try your plugin, but on my sublime text 2 rel. 2195 the plugin didn’t create file or directory, is possible that changes in the API breaks the program?

0 Likes

#6

Hi,

The plugin creates the file, but puts nothing inside. The console shows the contents of my template with the variables still there. Not sure what I am doing wrong. I am using Build 2181. Also, I can not hear anything in the video. I am running on a Windows 7 system. Have not tried it under Linux yet.

0 Likes

#7

Brilliant! Just what I was looking for, and am excited to try this out immediately! Thanks!

0 Likes

#8

2 apocalip

Can you add option, to create several files from one template?
like arguments:

<files>
    <file1>$name.php</file1>
    <file2>$name.bro.php</file2>
 </files>

<arguments>
    <name>Name:</name>
 </arguments>

It will be very useful.
Thanks.

0 Likes

#9

Hey, i’m trying to make a template for latex.
I guess i’ve to make a Latex.file-template file in /Templates. But when i open the command palette and select Create New Template i really don’t understand what is the idea of that file that pop’s up. Could you help me?

Thanks

0 Likes

#10

github.com/lawlist/ST2-plugin-Insert-File-Here

This is an insert file here plugin ST2 (OSX Mountain Lion), which is a modification of the plugin developed by the original poster.

0 Likes