Skip to content

How to create a document template from scratch

Marina Popleteeva edited this page Dec 10, 2024 · 4 revisions

Abbreviations

  • KM - Knowledge Model
  • DT - Document Template

Introduction

This is a guide on how to create a Document Template (DT) for a simple Knowledge Model (KM) from scratch. Such simple KM and corresponding template contains only Value-text questions with guidelines. Use case: a need to have a DSW version of a funder template (e.g. FNR or MRC). Steps to create more advanced structures such as tables and aesthetics are not part of this guide.

Additional material

Watch the video tutorial (you can skip "Installation of DSW TDK" and "Connection to DSW API" and start from 19:00).

Step-by-step guide:

  1. In DSW create a new DT editor following this guide.

    1. Leave the field “Based on” empty.
  2. Go to the “Settings” tab on the freshly created DT and

    1. fill all General settings;
    2. fill out the Knowledge Model(s), you wish the created doc template to be compatible with.
      1. leave the field “Max version” empty
    3. go to the “Formats” tab and add the formats you wish for the doc template.
      1. you can copy them from another DT, like Horizon Europe DMP template.
  3. Navigate to the “Files” tab and create the following:

    1. subfolder src
    2. inside scr create files
    • index.html.j2;
    • style.css;
    • uuids.j2.

At the end you will have something like this:

image

  1. Put the following skeleton into index.html.j2 (if needed, the file can be downloaded here):
<!DOCTYPE HTML>
{%- set km = ctx.knowledgeModel -%}
{%- set repliesMap = ctx.questionnaireReplies -%}
{%- set report = ctx.report -%}
{%- set dc = ctx|to_context_obj -%}
{% import "src/uuids.j2" as uuids with context %}
<html lang="en">
  <head>
    <title>Data Management Plan</title>
    <meta charset="utf-8">
    <style>
      {% include "src/style.css" %}
    </style>
  </head>
  <body>
      <h1>Test</h1>
    </article>
  </body>
</html>
  1. If you are going to use a generic template - display all questions and all answers - skip this step. Otherwise, use KM inside to populate uuids.j2 file (see another guide). TODO: change the link to another wiki page when ready.
  2. Setup Preview. You should see the word “Test”.

image

  1. Use the index file to create the content of the doc template. You can use the following video to guide you.
    • If your model is simple (a simple list of questions), you might want to check “Creating generic template” part of the video.
    • If your answers are big blocks of text, they might have several paragraphs. The following code to split them might be useful:
{%- if answer %}                
  {%- set paragraphs = answer.split('\n') -%}
  {% for paragraph in paragraphs %}
    <p>{{ paragraph }}</p>
  {% endfor %}
{%- endif -%}
  1. Optional: In the style.css file, you can format the layout of your doc template with CSS. An example is shown below:
body { 
font-family: sans-serif;}

h1 {
font-weight:bold;
text-align: center;
}
Clone this wiki locally