Imagine a scenario where I have an HTML template file with the following string:
<p> >>LEFT PART<< {{Data}} >>RIGHT PART<< </p>
Suppose that neither the left nor right part of this string contain anything like {{Data}}
, and I want to create a function that takes this file and an object such as
{Data:"My nice data",Name:"Sebastian"}
, and returns a file containing:
<p> >>LEFT PART<< My nice data >>RIGHT PART<< </p>
It is achievable using string.prototype.replace, but now I have a few questions:
- How do JS template engines handle similar tasks? Let's focus on Jade for specificity, but feel free to discuss other engines like Pug, Dot etc. Do they rely on Regular Expressions or use complex algorithms to search for substrings?
- If both the left and right parts of my string contain around 10000 characters, or if the HTML file encompasses over 100 lines of code, will there be a noticeable impact on execution speed if I utilize Regular Expressions?
P.S. While I've tried to find answers via Google, most resources explain how to render a page using a framework/engine rather than delving into the internal workings.