How to create document collections from a template
Skills required | XML |
---|---|
Time required (minutes) | 30 |
Intended audience | Developer |
Difficulty | Easy |
Category | Document |
Objective
Through the PageSeeder interface, document templates allow users to create single documents. This tutorial explains how developers can use a process script to have a document template create an entire collection of linked documents.
Use Case
Applications for this functionality are multi-document reports or publications that require components such as front matter, body and back matter.
Prerequisites
To complete this tutorial requires:
- Administrator access to a PageSeeder server.
- Knowledge of how to create projects, groups, folders and documents in PageSeeder.
Tutorial
Setup projects, groups and documents
- Create a project called “example”.
- In this project, create groups called “template” and “publication”.
- In “example-template” create a folder called “templates”.
- In “templates” create a folder called “publication1”.
- In “publication1” create one document with a type of “references”.
- From the “references” document, create and link a few documents with a type of “default” (these will form the template for one document collection).
- Repeat tasks 4-6 for a folder called “publication2”.
Setup process script
- In the “example” project and go the Project dashboard
- Select Publish scripts from the menu
- Click Configure scripts for group/folder/document.
- Replace the content with the following XML and click Save at the bottom (the
<value>
elements define your list of templates, so would need to be updated if you add or rename template folders).<publishing> <action type="process"> <source type="folder" /> <target name="create-collection"> <description>Create document collection</description> <param name="template-name" label="Template" type="select"> <!-- THE FOLLOWING VALUES SHOULD BE MODIFIED FOR EACH SPECIFIC PROJECT --> <value>publication1</value> <value>publication2</value> </param> <param name="collection-name" label="New collection name" type="text" /> </target> </action> </publishing>
- Return to the Publish scripts page and click Refresh
- Click create next to the “create-collection” target.
- Replace the content with the following XML and click Save (modify the
template-folder
property for a different project).
<project name="folder-process" xmlns:ps="antlib:com.pageseeder.publishapi.ant"> <target name="create-collection" description="Create document collection"> <!-- Folder containing the templates (MODIFY FOR SPECIFIC PROJECT) --> <property name="template-folder" value="/ps/example/template/templates" /> <!-- load PageSeeder config properties --> <ps:config /> <!-- create working folders --> <property name="download" value="${ps.config.default.working}/download" /> <property name="process" value="${ps.config.default.working}/process" /> <mkdir dir="${download}"/> <mkdir dir="${process}"/> <!-- export template documents --> <ps:export src="${template-folder}/${ps.param.template-name}" dest="${download}" /> <!-- remove docids to avoid clashes --> <ps:process src="${download}" dest="${process}" processed="false" preservesrc="true"> <strip documentinfo="docid" /> </ps:process> <!-- zip files to preserve folder structure on upload --> <zip destfile="${ps.config.default.working}/upload.zip" basedir="${process}" /> <!-- upload template documents to new location --> <script language="javascript"> var name = project.getProperty("ps.param.collection-name"); project.setProperty("foldername",name.toLowerCase().replaceAll(" ", "_")); </script> <ps:upload group="${ps.config.default.group.name}" folder="${ps.config.default.uri.path.no.group}/${foldername}" unzip="true"> <fileset file="${ps.config.default.working}/upload.zip" /> </ps:upload> <echo>Creation successful!</echo> </target> </project>
Create a collection
- In PageSeeder go to the 'example-publication' group and click on Documents.
- Next to the 'documents' folder select Process by mousing over the actions icon at right (this is where the document collection will be created, so you could select any folder).
- Select a Template from the drop down list and type a New collection name (e.g. My new publication)
- Click the Process button and wait until 'Creation successful!' appears.
- Click Close, then click on the documents folder and you should see the folder for your new collection with the documents from the template inside it.