m2doc

invalid type literal import - How to import and use my custom service


So I created a simple service with a single class, without constructor : services.RecursiveQuery and added it as a plugin to my Eclipse instance as described in this question.

According to the documentation the next step would be to import it in my template file file so I tried this:

{m:import:services.RecursiveQuery}

However I get this error in the validation file:

Expression "import:services.RecursiveQuery:services" is invalid: invalid type literal import:

What am I doing wrong ? It feels like I'm missing something. Also I was wondering how to use the getAllChildren() method of this service. I would have tried {m:for child | services.RecursiveQuery.getAllChildren(self)} but that doesnt feel right.


Solution

  • The M2Doc documentation may be unclear on this point: {m:import...} is not a valid statement in a M2Doc template file. It should be used in MS Word document properties, not in the docx template file.

    You should use the template properties wizard to change imports along with the solution you mentionned here.

    For a better understanding of how to use custom services you can check examples in M2Doc sources.