Summary (version 3.1.2) Demo Readme Changelog

This module makes it possible to create multiple slides with a loop in a pptx. For example, you could clone slides for each of your products. The whole order of the slides can be declared from the data.

This module is available as part of the docxtemplater pro plan.

Demo

Input Output
Data Code
{
    "slides": [
        {"$slide": 1, "title": "hi", "date": "ho"},
        {"$slide": 2, "subtitle": "hello"},
        {"$slide": 3, "image": "1"},
        {"$slide": 3, "image": "2"}
    ]
}
const doc = new Docxtemplater();
const inputZip = new JSZip(docX);
const slidesModule = new SlidesModule({});
doc.setOptions({fileType: "pptx"})
	.loadZip(inputZip)
	.setData(data)
	.attachModule(slidesModule);
const output = doc.render().getZip();

README

Installation:

You will need docxtemplater v3: npm install docxtemplater

Install this module with npm install --save "$url"

Usage

There are two ways of using the slides module. Explicit, where the developper specifies which slides to repeat, and Tagging, where the template creator chooses which slides to repeat from the template itself by tagging slides with a specific tag.

Explicit

If you use the explicit method, you write from the code which slides you want to repeat :

const SlidesModule=require('docxtemplater-slides-module')

const slidesModule=new SlidesModule()

const data= {
    "slides": [
        {"$slide":1,name:'Franck',phone:"+665432131"},
        {"$slide":1,name:'Jim',phone:"+6234468468"},
        {"$slide":1,name:'Joe',phone:"+78788787"},
        {"$slide":1,name:'Hugh',phone:"03566456465"},
    ]
}

docx
    .attachModule(slidesModule)
    .loadZip(zip)
    .setData(data)
    .render()

const buffer= docx
        .getZip()
        .generate({type:"nodebuffer"})

fs.writeFile("test.docx",buffer);

And in your template, write :

Slide1
------

{name} {phone}

You will then have slide 1 duplicated 4 times.

Tagging

If you want the template creator to choose which slides to repeat, use this way.

const SlidesModule=require('docxtemplater-slides-module')

const slidesModule=new SlidesModule()

const data= {
    mainTitle: "My title",
    users: [
        {name:'Franck',phone:"+665432131"},
        {name:'Jim',phone:"+6234468468"},
        {name:'Joe',phone:"+78788787"},
        {name:'Hugh',phone:"03566456465"},
    ],
    foo: "bar",
}

docx
    .attachModule(slidesModule)
    .loadZip(zip)
    .setData(data)
    .render()

const buffer= docx
        .getZip()
        .generate({type:"nodebuffer"})

fs.writeFile("test.docx",buffer);

And in your template, write :

Slide1
------

{mainTitle}
Slide2
------

{:users}
{name} {phone}

In this case, the slide2 will be repeated 4 times (since users is an array of 4 elements, and slide1 will appear once.

Special Features

Everything that is outside of the "slides" key is automatically accessible from all templated slides.

You can use the special variables {$count} and {$index} in your template to get the index of the current slide, and the total count of the slides (in the expected output).

CHANGELOG

3.1.1

Bugfix : Slide 10 and following slides are no longer removed

3.1.0

Add possibility to tag slides for repetition with {:users}

3.0.3

Add compatibility with image-module

3.0.2

Exported files are now ES5

3.0.1

Bugfix : Slides module doesn't throw an error anymore when templating docx files

3.0.0

Initial release

Edgar Hipp

I'm the creator of docxtemplater. I work on making docxtemplater great since 2013.