0

I am trying to render an HTML file using puppeteer and handlebars while storing the HTML file in the hbs template and rendering it on the go.

The issue is I am not able to fetch the data onto the script tag using the "{{variable}}" syntax, which handlebars usually generate if they are in HTML tags, but do not happen in the script tag.

One of the methods I saw was to render the value inside the input tag, and then calling the dom object to fetch the value like :

<input type = "hidden" id = "Labels" value = {{Labels}} />

and then accessing this using :

const Labels = JSON.parse(document.getElementById("Labels").value);

Is there any other method that I can do to render the HTML file using some other libraries or a way around this itself?

  • Is this post helpful to you?: https://stackoverflow.com/a/64419864/3397771 – 76484 Sep 29 '22 at 10:49
  • Not exactly, but I somehow managed to solve the issue. You will have to render the data in the html tag only and make sure that the style of the tag is hidden, after that you will have to use DOM to get the data like I did. Only issue is you will have to change the format of the data after you received it, to your desired choice – Sarthak Agarwal Oct 10 '22 at 06:17
  • It might the right thing to do to either post your solution or remove your question so that others don't spend time on a problem you have already solved. – 76484 Oct 11 '22 at 00:38
  • Sure thing, but there is already an answer available which is what I did. – Sarthak Agarwal Oct 11 '22 at 07:01
  • Does this answer your question? [Access handlebars properties from script tag](https://stackoverflow.com/questions/37115630/access-handlebars-properties-from-script-tag) – 76484 Oct 11 '22 at 10:56

1 Answers1

0

This is a similar approach and the answer to this.

Access handlebars properties from script tag

Only issue is you will have to change the format of the data after you received it, to your desired choice