LoginSignup
5
5

More than 5 years have passed since last update.

Ractive.jsのテンプレートに外部ファイルを使用する

Last updated at Posted at 2014-12-17

ここを読んだほうが早い


サンプルはこれ

( ^ω^) ここに 公式 60-second-setup があるじゃろ?

( ^ω^) これを…

index.html
<div id='container'></div>

<script id='template' type='text/ractive'>
  <p>Hello, {{name}}!</p>
</script>

<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>

<script>
  var ractive = new Ractive({
    el: 'container',
    template: '#template',
    data: { name: 'world' }
  });
</script>

( ^ω^) こうじゃ

hello.html
<p>Hello, {{name}}!</p>
index.html
<div id='container'></div>

<!-- これは不要
<script id='template' type='text/ractive'>
  <p>Hello, {{name}}!</p>
</script>
 -->

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>

<script>
  $.get('hello.html').then( function(template) {
    var ractive = new Ractive({
      el: 'container',
      template: template,
      data: { name: 'world' }
    });
  });
</script>

以上

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5