Code Templates - Easily Apply Templates to Your Scripts

Code Templates is a plugin that allows scripters to quickly reuse templates without having to copy and paste between other scripts.

Download

Features

  • Name, Roblox Username, and current date replacements
  • Can be applied with --$TemplateName in scripts or with CollectionService tags
  • UI changes based on theme

Documentation

Create new templates with the “+ Add” button

image

Add tags to be replaced dynamically

Using the tags $NAME$, $ROBLOXSTUDIOUSERNAME$, and $CURRENTDATE$ in your template replaces them when using them within a script.

Add templates when inserting scripts using CollectionService tags

Adding a CollectionService tag to any instance that has the same name as a code template will cause any children inserted to get the code template.

Note: This only applies to direct children

T1QCehExbV

Apply a template in a script with --$TemplateName

Typing --$TemplateName in a script where TemplateName is the name of a template you have will replace it with the template.

FsDAJtjcoV

UST1rwAGlp

:warning: Notice:
In Team Create you will need to commit the script when using this feature for the changes to apply.

Import Codes

Use these codes by right clicking the add button, selecting import, and pasting one of the below codes.

Knit

BQAADktuaXRDb250cm9sbGVyAADPbG9jYWwgS25pdCA9IHJlcXVpcmUoZ2FtZTpHZXRTZXJ2aWNlKCJSZXBsaWNhdGVkU3RvcmFnZSIpLktuaXQpCgpsb2NhbCAkTkFNRSQgPSBLbml0LkNyZWF0ZUNvbnRyb2xsZXIgewogICAgTmFtZSA9ICIkTkFNRSQiOwp9CgpmdW5jdGlvbiAkTkFNRSQ6S25pdFN0YXJ0KCkKZW5kCgpmdW5jdGlvbiAkTkFNRSQ6S25pdEluaXQoKQplbmQKCnJldHVybiAkTkFNRSQKAAANS25pdENvbXBvbmVudAABoWxvY2FsIEtuaXQgPSByZXF1aXJlKGdhbWU6R2V0U2VydmljZSgiUmVwbGljYXRlZFN0b3JhZ2UiKS5Lbml0KQpsb2NhbCBNYWlkID0gcmVxdWlyZShLbml0LlV0aWwuTWFpZCkKCmxvY2FsICROQU1FJCA9IHt9CiROQU1FJC5fX2luZGV4ID0gJE5BTUUkCgokTkFNRSQuVGFnID0gIiROQU1FJCIKCmZ1bmN0aW9uICROQU1FJC5uZXcoaW5zdGFuY2UpCiAgICBsb2NhbCBzZWxmID0gc2V0bWV0YXRhYmxlKHt9LCAkTkFNRSQpCiAgICBzZWxmLl9tYWlkID0gTWFpZC5uZXcoKQogICAgcmV0dXJuIHNlbGYKZW5kCgpmdW5jdGlvbiAkTkFNRSQ6SW5pdCgpCmVuZAoKZnVuY3Rpb24gJE5BTUUkOkRlaW5pdCgpCmVuZAoKZnVuY3Rpb24gJE5BTUUkOkRlc3Ryb3koKQogICAgc2VsZi5fbWFpZDpEZXN0cm95KCkKZW5kCgpyZXR1cm4gJE5BTUUkCgAAC0tuaXRSZXF1aXJlAABAbG9jYWwgS25pdCA9IHJlcXVpcmUoZ2FtZTpHZXRTZXJ2aWNlKCJSZXBsaWNhdGVkU3RvcmFnZSIpLktuaXQpCgAAC0tuaXRTZXJ2aWNlAADdbG9jYWwgS25pdCA9IHJlcXVpcmUoZ2FtZTpHZXRTZXJ2aWNlKCJSZXBsaWNhdGVkU3RvcmFnZSIpLktuaXQpCgpsb2NhbCAkTkFNRSQgPSBLbml0LkNyZWF0ZVNlcnZpY2UgewogICAgTmFtZSA9ICIkTkFNRSQiOwogICAgQ2xpZW50ID0ge307Cn0KCmZ1bmN0aW9uICROQU1FJDpLbml0U3RhcnQoKQplbmQKCmZ1bmN0aW9uICROQU1FJDpLbml0SW5pdCgpCmVuZAoKcmV0dXJuICROQU1FJAoAAAhMdWFDbGFzcwAArmxvY2FsICROQU1FJCA9IHt9CiROQU1FJC5fX2luZGV4ID0gJE5BTUUkCgpmdW5jdGlvbiAkTkFNRSQubmV3KCkKICAgIGxvY2FsIHNlbGYgPSBzZXRtZXRhdGFibGUoe30sICROQU1FJCkKICAgIHJldHVybiBzZWxmCmVuZAoKZnVuY3Rpb24gJE5BTUUkOkRlc3Ryb3koKQoKZW5kCgpyZXR1cm4gJE5BTUUkCg==

83 Likes

Great! it tooks a while to give the credits. :smiley:

3 Likes

Infinite name thing:
For example, the name of the script is called “Testing”
and you put --$Testing script$ at the top, it continuously adds to the script, and it should clear the script and add the template instead of adding it onto the script, or have it be toggleable.
Edit: other than that this is really useful.

1 Like

I designed it so that it doesn’t clear the script when inserting a template. With this you have more options on what to do. You can either select everything and replace it with --$TemplateName or you could add it somewhere else in a script like this.

UST1rwAGlp

3 Likes

It would be nice to have a clearing a setting that you set like in the script you will put in the script that you put the template in, did that make sense? I’ve got no clue.

2 Likes

I’ll implement a way to change this behavior in a future update.

1 Like

I have released a new update that adds this functionality. Using --$TemplateName will continue using the old way, while --$$TemplateName will replace the entire script.

1 Like

Nice, and a good way of implementing it.

1 Like

Oh. I went through this before and didn’t realize how actually useful this is for module building. This is such a good resource, thanks I’ll be sure to try it :), are there any already existing templates?

1 Like

Does this plugin correctly handle the case where someone writes --$TemplateName in a string? e.g print("--$TemplateName") ?

3 Likes

This cannot happen as far as I know. is a comment in Lua, which is ignored, so that is the same as doing print(“.

1 Like

Sorry, I think I gave a bad example. What about a case like:

print(
[[
--$TemplateName
aaaaaaaaaaa
idk why someone would do this but they probably will
]]
)
1 Like

I don’t think this is handled correctly currently. I might fix this in an update sometime, but it’s not a priority right now because it seems like something that will never happen.

4 Likes

The plugin does not come with any templates built in. I will add an export and import feature in the future for sharing templates.

Templates are pretty easy to make. Here’s one I use for a class.
image

3 Likes

I’m not familiar with import codes. What tool is this for and what does it do?

2 Likes

In a future version of Code Templates I plan to add a way to export templates that you’ve created to share with other users. Right now you can only import templates. The import codes can be used by right clicking “+ Add” and selecting import. For example, by using the Knit import code some Knit tenplates are added (KnitService, KnitController, and KnitComponent).

1 Like

This is awesome! Great contribution.

1 Like

Hate to bump this, but is there any updates done on this? This seems really useful and I would love to see a way to export our own templates.

1 Like

I’ve been working on an update for this plugin to add lots of new features, but it’s currently blocked by some things outside my control.

1 Like

Oh dang! Well hopefully these said restrictions are eased, thanks for responding either way!

1 Like