1.0.0 • Published 6 years ago

both-render v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

both-render

render in server and browser

代码

模板:assets/views/main.tpl

{{title}}
<footer id="id-auth"></footer>
{{hack}}
<script id="id-tpl" type="text/html">
{{author}}
</script>
<script>
(function(){
  let tpl = document.querySelector('#id-tpl').innerHTML;
  let html = vtpl(tpl, {
    author: 'hitvalley'
  });
  document.querySelector('#id-auth').innerHTML = html;
}());
</script>
{{/hack}}

server端运行

{{title}}
<footer id="id-auth"></footer>

client端运行

{{hack}}
<script id="id-tpl" type="text/html">
{{author}}
</script>
<script>
(function(){
  let tpl = document.querySelector('#id-tpl').innerHTML;
  let html = vtpl(tpl, {
    author: 'hitvalley'
  });
  document.querySelector('#id-auth').innerHTML = html;
}());
</script>
{{/hack}}

run

npm start

# 访问:http://localhost:8080

结果

image