VolkovLabs / business-text

The Business Text panel plugin allows you to construct a text visualization template from the values of a dataset returned by a data source query.
https://docs.volkovlabs.io
Apache License 2.0
81 stars 13 forks source link

handlebars is not defined #302

Closed p-wieser closed 5 months ago

p-wieser commented 6 months ago

Hello,

Well, all is in the title : when trying to call handlebars.registerHelper(), I get this error. Just to be sure, here is the offending line:

handlebars.registerHelper("myResult", () => { return myData; });

I do not see where the error is. Surely other eyes will just see it at first glance (I hope !) I run DynamicText 4.5.0 with Grafana 9.2.10

Could you please explain how to declare the handlebars context ? Thanks in advance. Best regards Pierre

p-wieser commented 6 months ago

Precision: the call is from JS code "After Content Ready".

mikhail-vl commented 6 months ago

@p-wieser We defined all parameters in After Content Ready as a part of the context.: https://volkovlabs.io/plugins/volkovlabs-dynamictext-panel/code/

p-wieser commented 6 months ago

Sorry, I do not understand your answer. First, the documentation explicitly says to call "handlebars.registerHelper()", not context.handlerbars.... The screenshot in the doc is same (also directly invokes handlebars object). Second, my context only contains :

console.log( context );
    data
    dataFrame
    element
    grafana
        eventBus
        getLocale
        locationService
        notifyError
        notifySuccess
        replaceVariables
        theme
        timeRange
        timezone
    panelData

and nothing else. In particular, the context.handlebars said by the documentation is not here.

So could you be kind enough to explain a bit more, please ? Thanks in advance. Regards

mikhail-vl commented 6 months ago

@p-wieser Oh, I am sorry for the confusion. handlebars are not available in the After Content Render.

Additional Handlebars should be created in Before content Render, because they are used during the rendering process to convert Handlebars -> Markdown -> HTML. We may need to update documentation to make it clear if it's not.

After Content Render works with already created HTML elements and handlebars are not available at this point. Let me know if it's clear.

p-wieser commented 6 months ago

Ah, yes, I understand now :) And, yes, I believe that this could be more clear in the documentation, or at least just specified by the fact. Thanks for your help. Regards Pierre

mikhail-vl commented 5 months ago

Documentation updated: https://volkovlabs.io/plugins/volkovlabs-dynamictext-panel/code/#custom-handlebars-helper