Warning

The XML-RPC API is no longer under active development. While it is still supported, no further improvements or changes will be made to it.

We strongly recommend that you use the REST API instead.

Manipulating Templates

The ActionKit CMS is powered by templates, organized into template sets. You can access these objects through the API. You might use this interface to create an enhanced template editing environment or tie ActionKit templates into your version control system.

Reading Templates

You can access template objects the same way you access other ActionKit objects. For example, here's code to print out the name and contents of all the templates in the Original templateset:

import xmlrpclib

actionkit = xmlrpclib.Server('https://%s:%s@%s/api/' % (user,password,host))

# find the Original templateset
(original,) = actionkit.TemplateSet.search({ 'name': 'Original' })

# load all templates in the original set
templates = actionkit.Template.search({ 'templateset': original['id'] })

for template in templates:
    print "Template Name: %s" % template['filename']
    print "#########################################"
    print template['code']

Hint

See Setup for the hostname, user and password.

Writing Templates

Writing to templates is as simple as calling save() with new data for the 'code' attribute. Here's an example which overwrites donate.html in the "New" templateset with new data:

import xmlrpclib

actionkit = xmlrpclib.Server('https://%s:%s@%s/api/' % (user,password,host))

# find the New templateset
(new,) = actionkit.TemplateSet.search({ 'name': 'New' })

# find the donate.html template
(donate,) = actionkit.Template.search({ 'templateset': original['id'],
                                        'filename'   : 'donate.html' })

# new code to save - could read from a file here for example
code = "Here's my new HTML!"

# save new code
actionkit.Template.save({ 'id': donate['id'],
                          'code': code })