# Template versioning and "includes"

**URL:** <https://community.transloadit.com/t/template-versioning-and-includes/18312>\
**Category:** Transloadit\
**Tags:** tender-archive\
**Created:** [June 4, 2014, 10:34pm UTC](https://community.transloadit.com/t/template-versioning-and-includes/18312 "2014-06-04T22:34:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergey](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/sergey/32/1645_2.png) [@sergey](https://community.transloadit.com/u/sergey)\
**Post date:** [June 4, 2014, 10:34pm UTC](https://community.transloadit.com/t/template-versioning-and-includes/18312/1 "2014-06-04T22:34:00Z")

</div>

> Archived from the Transloadit support forum. Originally posted on June 4, 2014; details may be outdated, see [our docs](https://transloadit.com/docs/) for current behavior. [Original thread](https://web.archive.org/web/20150502074117/http://support.transloadit.com/discussions/suggestions/10719-template-versioning-and-includes)

Hi Guys,  
I have quite a lot of templates, and management of these templates and version control is becoming a hassle. I am currently keeping them in my github repo and sync them using transloadit API.

Couple of things would be of use to someone like me:  
1. Ability to reference or “include” common template steps. I would be able to create some kind of code reuse.  
2. Template version control (rollback to previous version). I would advise to integrate with github here and allow us to store our templates in github. Although, there are other alternatives here obviously.

I created a nodejs coffeescript to sync up my templates stored in local files to transloadit. It is not the most brilliant piece of engineering, but I will share it here for anyone to use.

Run via coffee script

```auto
coffee myscript.coffee

```

Code:

```auto
_ = require 'lodash'
request = require 'request'
url = require("url")
crypto = require("crypto")
moment = require('moment')
fs = require('fs')
path = require('path')

authKey = "mykey"
authSecret = "mysecret"

getTemplates = (next = ->)->
  expires = moment().add('hours', 3).utc().format("YYYY/MM/DD HH:mm:ssZ")
  params =
    auth:
      expires: expires
      key: authKey
  paramsString = JSON.stringify(params)
  signature = crypto.createHmac("sha1", authSecret).update(new Buffer(paramsString, "utf-8")).digest("hex")
  request.get
    url: "https://api2.transloadit.com/templates?params=#{encodeURIComponent(paramsString)}&signature=#{signature}"
    json: true
  , (err, r, body)->
    return next(err) if err
    if r.statusCode is 200
      next(null, body)
    else
      next(body)

updateTemplate = (templateId, templateName, templateBody, next=(->))->
  expires = moment().add('hours', 3).utc().format("YYYY/MM/DD HH:mm:ssZ")
  params =
    auth:
      expires: expires
      key: authKey
    name: templateName
    template: templateBody
  paramsString = JSON.stringify(params)
  signature = crypto.createHmac("sha1", authSecret).update(new Buffer(paramsString, "utf-8")).digest("hex")
  request.put
    url: "https://api2.transloadit.com/templates/#{templateId}"
    json:
      signature: signature
      params: paramsString
  , (err, r, body)->
    return next(err) if err
    if r.statusCode is 200
      console.log "[OK] #{templateId} -", body.ok
      next(null, body)
    else
      console.log "[ERROR] #{templateId} -", body
      next(body)

templateFiles = fs.readdirSync("templates")
getTemplates (err, templatesResponse)->
  if err
    return console.log "Error loading templates", err
  for templateFile in templateFiles
    try
      template = JSON.parse(fs.readFileSync(path.join("templates", templateFile), "utf8"))
      templateName = templateFile.replace(path.extname(templateFile), '')
      existingTemplate = _.find templatesResponse.items, (item)->item.name is templateName
      if existingTemplate
        console.log "UPDATING", existingTemplate.id, existingTemplate.name
        updateTemplate(existingTemplate.id, existingTemplate.name, template)
    catch err
      console.log "Cannot process file #{templateFile}", err

```

---

<div class="post-metadata">

**Author:** ![tim-kos](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@tim-kos](https://community.transloadit.com/u/tim-kos)\
**Post date:** [June 5, 2014, 6:13am UTC](https://community.transloadit.com/t/template-versioning-and-includes/18312/2 "2014-06-05T06:13:00Z")

</div>

Hey Sergey,

thank you for sharing this! You should add this to a public repository so that we can link it in our community projects section.

Regarding your advice about template includes and versioning: Yes, that is on our radar as a few people have requested this. It’s almost certain that something like this will be available in the future. We cannot tell you when, though.

Kind regards,  
Tim

Co-Founder Transloadit  
@tim\_kos

---

<div class="post-metadata">

**Author:** ![tim-kos](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@tim-kos](https://community.transloadit.com/u/tim-kos)\
**Post date:** [June 24, 2014, 8:59am UTC](https://community.transloadit.com/t/template-versioning-and-includes/18312/3 "2014-06-24T08:59:00Z")

</div>

Hey Sergey,

have you added this to a public repository yet?

Kind regards,  
Tim

Co-Founder Transloadit  
@tim\_kos

---

<div class="post-metadata">

**Author:** ![tim-kos](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@tim-kos](https://community.transloadit.com/u/tim-kos)\
**Post date:** [April 28, 2015, 1:20pm UTC](https://community.transloadit.com/t/template-versioning-and-includes/18312/4 "2015-04-28T13:20:00Z")

</div>

This discussion has been inactive for 30 days and has been marked as resolved automatically.  
Feel free to reply to this ticket to re-open it and we will continue the investigation.

Kind regards,  
Tim

Co-Founder Transloadit

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex032/uploads/transloadit/original/1X/04ee57da0cb7ac8728a9ac5965c288164f4ce280.svg) [@system](https://community.transloadit.com/u/system)\
**Post date:** [October 7, 2026, 10:56am UTC](https://community.transloadit.com/t/template-versioning-and-includes/18312/5 "2026-10-07T10:56:18Z")

</div>


