Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to insert a link in docx in docxtemplator 3.0? #408

Closed
zmaks100 opened this issue Jul 22, 2018 · 3 comments
Closed

How to insert a link in docx in docxtemplator 3.0? #408

zmaks100 opened this issue Jul 22, 2018 · 3 comments
Labels

Comments

@zmaks100
Copy link

Looks like there is a solution for inserting links for docxtemplator 2.0 using docxtemplater-link-module. But this module doesn't work with docxtemplator 3.0:

Uncaught Error: This module cannot be wrapped, because it doesn't define any of the necessary functions
    at ./node_modules/docxtemplater/js/module-wrapper.js.module.exports (module-wrapper.js:25)

I wonder whether docxtemplator 3.0 provides link support out-of-the-box? Or is there a guidance how to convert modules from v2 to v3?

@edi9999
Copy link
Member

edi9999 commented Jul 23, 2018

I think the module should support v2 as well as v3.

You have to write :

var LinkModule = require('docxtemplater-link-module');
var linkModule = new LinkModule();
var docx = new DocxGen()
	.attachModule(linkModule)

You probably forgot the new

@edi9999 edi9999 closed this as completed Jul 23, 2018
@zmaks100
Copy link
Author

Hmmm. The changelog.md clearly says 'The module system was completely changed, no compatibility is kept between version 2 and version 3, please make sure to update your modules if needed.'. I also can see active issue for this link module: issue.

Here is my sample:

    public static GenerateReport(): void {
        let content = fs.readFileSync(path.resolve("./", "./test/assets/input.docx"), "binary");
        let zip = new JSZip(content);
        let doc = new Docxtemplater();
        let linkModule = new LinkModule();
        doc.attachModule(linkModule);
        doc.loadZip(zip);

        //set the templateVariables
        doc.setData({
            first_name: "John",
            last_name: "Doe",
            phone: "0652455478",
            description: "New Website",
            treatmentIssues: [
                {
                    fact: 'The first fact',
                    source: 'https://bing.com'
                }
            ]
        });

Docxtemplator throws an error from attachModule saying that it didn't find any important functions. They are indeed not there.

Double checking - does Docxtemplator v3 supports modules written for v2?

PS: new is there :)

@edi9999
Copy link
Member

edi9999 commented Jul 23, 2018

Ok indeed, I see, you're right, the two modules systems are incompatible.

In the link-module, you have functions defined as :

get, handle, and handleEvent. Those were the v2 API methods.

The current API methods are render, parse, postparse, ... (see https://github.com/open-xml-templating/docxtemplater/blob/master/es6/module-wrapper.js#L6 for full list)

You can find example modules on https://github.com/open-xml-templating/docxtemplater/blob/master/es6/modules/render.js (they are other modules in these directories).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants