Ask HN: Server-side HTML Templates based on DOM?
For instance the "main template" for a site could be an HTML page that has a <article> inside it which is a placeholder for the content. The content is itself an HTML page, and the <body> of the content is inserted into the <article>, also the metadata gets merged so the <title> passes through.
You might write
<div>First Name: <span id="#insertFirstName"></span></div>
and the system would insert the firstName into that span, for instance.I've done the same thing in Java with tools like jsoup and HTMLUnit.
This system can rewrite links and do other interesting transformations on the guest HTML.
One thing I'll concede is that this is slow compared to the alternatives. In a crude test a system like this and not optimized might be able to transform 10-50 pages per second on a core whereas it is easy to get 3000+ with string based templates.
I haven't seen other people do this, are there any examples you of know of DOM-based templating? Any thoughts?