Ad
Node.js & Mustache.js: How To Separate Server-side Rendering Than Client-side Mustache Templating?
I try to render second.html
with server-side after validating a form in home.html
, then keep mustache.js to template (update) parts from second.html
as user validates new form in it (multiple times).
problem: html renders the parameters from server-side but sees parameters from mustache as empty strings
I knew that mustache can work for both server and client side but I didn't use mustache in the server files
server-side file
var serverSideParameter = 'server'
res.render('chat.html', { serverSideParameter })
client-side file
var clientSideParameter = 'client'
const html = Mustache.render(Template, { clientSideParameter })
document.querySelector('#Container').innerHTML = html;
html file
<div id="Container"></div>
<p> {{serverSideParameter}} </p>
<script id="Template" type="text/html">
<p> {{clientSideParameter}} </p>
</script>
output:
<div id="Container">
<p></p>
</div>
<p>server</p>
Desired output:
<div id="Container">
<p>client</p>
</div>
<p>server</p>
Ad
Answer
I found the solution
define them into the client-side js file
res.send()
didn't work for me
Ad
source: stackoverflow.com
Related Questions
- → October CMS create a multi select Form field
- → How to update data attribute on Ajax complete
- → laravel blade templating error
- → should I choose reactjs+f7 or f7+vue.js?
- → How to dynamically add class to parent div of focused input field?
- → Setting the maxlength of text in an element that is displayed
- → Undefined Result for Variable with Javascript innerHTML function
- → Expanding search bar not expanding before search
- → Get the calling element with vue.js
- → Blade: how to include a section in one page but not in another
- → How to print/log reactjs rendered dom?
- → how to write react component to construct HTML DOM
- → How to add a timer in HTML5 and Javascript?
Ad