Skip to content

Instantly share code, notes, and snippets.

@yarcowang
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save yarcowang/8969090 to your computer and use it in GitHub Desktop.

Select an option

Save yarcowang/8969090 to your computer and use it in GitHub Desktop.
what about adding a internal template engine into html5?

// this is a mail for suggesting adding internal template engine into html5

Hi Sir:

I'm a php developer who sometimes touch javascript. I think there might be requirements for adding internal template system into modern browser.

Normally js lib would like to do this (for example in backbone):

<script type="text/template" id="...">
...
</script>

Obviously we need a common tag for that purpose when comparing to script/css links:

  • script with src attribute can link to those common javascript files
  • link with href attribute can link to those common css styles

What about common html templates? We could define the same thing for this:

// index.html
<tpl local id="tpl-foo">...</tpl>

// tpls.html
<tpl global id="tpl-bar">...</tpl>

The differences between use <script> and <tpl> are as folloing:

  • global templates will be cached just like cookie/localStorage
  • they can be obtained by the template engine, document.getTemplateById('tpl-foo')
  • they are hidden doms (so, there's no need extra step of parsing from string to dom -- like angularJs)
  • also support json as arguments. document.getTemplateById('tpl-foo').with(...json data...)

So what about this?

Thanks.

Yarco

@yarcowang
Copy link
Author

@yarcowang
Copy link
Author

There is also:

Something similar as what i'm thinking in template system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment