Is it possible to update properties of the template before engine runs?
-
I'd like to change the chrome template's "format" property based on dynamic data that gets processed by the engine and have it override the default template's format.
For example:
req.template.chrome.format = 'Legal';
would overwrite the template's default setting of "Letter" if the height of the report's html exceeded a certain size.
Is this possible?
-
hi, you can change chrome options in a
beforeRender
scripts that uses your data with some conditions, that is possible (example of that here), but i don't think it is possible to change it at the same time that knowing how much size your actual html is going to take, since in abeforeRender
script nothing is rendered yet and you don't know yet how much height the html is going to consume
-
I think I'd need something similar to pdfUtils to inject data back into the req object and also a new beforeEngineRender global function to set the the new template config. I imagine it would only be possible with a new custom extension.
-
pdfUtils just modifies the pdf output directly and adds some content based on the output of other template renderings, it does not modify req object in order to change how a single render will end, it actually modifies the raw pdf output directly. with that in mind and following the same idea of pdfUtils you can probably transform pdf to match new dimensions, but not sure how well a transform like that will be.
beforeRender
is run before template engines so it will be the same as thebeforeEngineRender
that you are suggesting.
-
I should have called it
beforeRecipeRender
. I see that the reporter also hasafterTemplatingEnginesExecutedListeners
. I could probably take the scripts extension and add support for that handler.PdfUtils embeds hidden html in the template engine output, I could similarly embed that html and parse it in
afterTemplatingEnginesExecuted
.
-
Here's an easier way to do it:
-
hey nice trick 😄! i completely forgot that we have such dynamic possibilities to change options in runtime, we will discuss this internally and see if it does makes sense for other cases or it it has some downside, thanks.