• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Mustache.js render function returning empty string for page rendered using Chevron

Resolved: Mustache.js render function returning empty string for page rendered using Chevron

0
By Isaac Tonny on 04/04/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve Mustache.js render function returning empty string for page rendered using Chevron

Question:

I have the following code to display a webpage using Mustache templating (simplified for clarity)
I expect the value of newHTML to be “tacos” but instead it’s an empty string. I suspect this has something to do with the fact that the page itself is initially rendered from Python using Chevron (I can’t get around that, it’s part of a larger codebase). I tried making the same page in a standalone HTML file and the value of newHTML is indeed set to “tacos”
Please help! Just spent half my day going in circles with ChatGPT
I’ve tried using different versions of Mustache.js, using a try/catch block, simplifying my code, console logging all the variables, and the issue still persists.

Best Answer:

Your suspicion is likely to be correct: Chevron encounters the {{food}} and replaces it with the empty string before the browser and Mustache.js can have a go at it.
You can prevent this from happening by temporarily changing the tag delimiters around parts of the template that should be rendered at the client side. Chevron will no longer recognize {{food}} as a tag and leave it alone. Conveniently, it will strip out the change delimiter tags, so the client will not see them.
For example, you can change the line with your client side template to this:
In this example, I put the change delimiter tags tightly around {{food}}. This is not necessary; to Chevron, everything looks like plain text, so you can put the tags anywhere. If there is a part of the page with only client side templates and no tags that should be processed by Chevron, you can wrap the entire section in a single pair of change delimiter tags. For example like this:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

html javascript mustache python templates
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to stop a thread that has a blocking function from easygui in python

05/04/2023

Resolved: Removing null keys from a json array of objects

05/04/2023

Resolved: How can I generate at compile-time a separate OpenAPI Swagger.json file for each Controller in my ASP.NET project?

05/04/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.