Create template with code (programmatically) with/without API?

Hello! I’d like to see if it’s possible to create layouts and pages directly with code (in VS Code an such).

Based on this doc, it says that we could create .tco files https://theme.co/docs/templates-api
However, I don’t seem to find where/how to do that, is there other, more detailed or specific doc for this?

Thanks in advance!

Hi Jorge,

It is not very clear what exactly you are trying to acheive here. If you want to create pages and page templates through coding, that is possible, but it requires custom coding, and you need to hire a developer who can assist you in doing the customization, or you can avail yourself of our service called One TOTAL CARE, where we offer small customizations.
Also, the documentation explains how you can create and import an import.tco programatically, and not related to what you are expecting here.

If that is not the case and you are trying to point out something else, you can elaborate on it a bit more for further assistance.

Thanks

Thanks @tristup,
What I want to achieve is to be able to create a Page for a site using VS Code (hand-coded basically) and being able to save it as a .tco file so I can upload it in a website that has PRO Theme.

So any pointers in the right direction if that’s possible would be highly appreciated.

Hello @lesthertod,

Thank you for the update.

The Templates API doesn’t actually allow you to create pages or templates using code. The functions are used to export a document from one installation and import it back to another, using a .tco file as the source. This .tco file can be generated by exporting an existing template from the Template Manager.

For more details, please check the documentation: https://theme.co/docs/template-manager

Hope this clear things up a bit.

Best regards,

Thanks for the clarification regarding the API features and limits regarding Templates @Ismael.

Can I create or edit a .tco file using VS Code? To then import it to the Template Manager in the site?

The same way that a WP Template file can be modified outside WordPress and then added to the site for example, I can edit the single-custompost.php on an IDE and then add it to the site. But in this case, it is the .tco file and added back to the Pro Theme / Cornerstone Template Manager.

The .tco file is actually just a zip file with a collection of JSON files inside it. There might be a VS Code extension to open and edit zip files. If you edit a document inside the .tco file and resave the zip, you should be able to just re-import inside Cornerstone. Start with the manifest.json file for more info on how it works. You’ll see something called “strategy”. If that is set to “replace” it will replace documents instead of creating a new document.

Awesome, thanks @charlie!

I see that the manifest has got 4 pairs inside the tasks/doc:

  1. Type, which I guess will almost always be Template.
  2. Strategy, that’s what you mention that could be switched to “replace” if I want to update instead of having a “new” copy.
  3. key
  4. file, these last two seems to be the reference to the JSON that has the actual page structure/content and such.

If I were to create one from scratch, is there’s any specific requirements for the key format? And is there any serialization or processing needed?

You’ll just need to make sure there is a manifest.json file. The document ID format could be made up by you, as well as how the image IDs work. Just export a couple more pages and you’ll get to see more examples. The .tco file is just a zip file so when you are done with your folder you’ll just need to zip it, and then rename the extension to .tco.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.