Custom metadata on template - Best practice?



  • Currently I'm storing some custom metadata in the template like this:

    {{!-- metadata{
      "title": "Xmas Card",
      "uipath": "aika/web/person",
      "accept": "person",
      "mimetype": "message/rfc822"
     }--}}
    From: kontakt@septima.dk
    To: {{email}}
    Subject: Merry Xmas
    
    
    You and your family ...
    

    This means I can expose a service to inform clients (system to system) which templates exist, what data they accept and return, and finally give them a user friendly title to display to the end user:

    [
        {
            "title": "Personoplysninger",
            "mimetype": "application/pdf",
            "uipath": "aika/web/person",
            "accept": "person",
            "id": "LmNeYrxmvHFE8HQD",
            "template": "personinfo"
        },
        {
            "title": "Xmas Card",
            "mimetype": "message/rfc822",
            "uipath": "aika/web/person",
            "accept": "person",
            "id": "Y6rQ0wf5BYAWw6tT",
            "template": "xmasmail"
        }
    ]
    

    Is there a better way of doing this? I've had a look at the localization extension which seems the closest to what I need.
    Is that the way to go, should I continue what I'm doing, or have I missed something?

    Thank you



  • What you do is likely the best. If you find it messy in the future, you can think about the following ideas...

    Another option is to have a convention, that in the same folder as the template, you will have also an asset with the metadata.
    sometemplate
    sometemplate-metadata.json

    And another option is to implement a custom extension that adds an extra field to the template and some modal to the studio so you can update it.
    https://jsreport.net/learn/custom-extension



  • Thank you very much. I'll look into a custom extension. It'd be great to ensure that the properties I need are set

    Will an extension be able to serve a reply to eg http://localhost:5488/my-extension/templates (such that I don't need to wrap jsreport in my own webapp)

    [
        {
            "title": "Personoplysninger",
            "mimetype": "application/pdf",
            "uipath": "aika/web/person",
            "accept": "person",
            "id": "LmNeYrxmvHFE8HQD",
            "template": "personinfo"
        },
        {
            "title": "Xmas Card",
            "mimetype": "message/rfc822",
            "uipath": "aika/web/person",
            "accept": "person",
            "id": "Y6rQ0wf5BYAWw6tT",
            "template": "xmasmail"
        }
    ]
    

    Thank you



  • An extension can do everything :)
    You will just need to do some studying of the existing extensions, because it is poorly docummented.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.