テンプレートに従って処理する

書式

template.evaluate({ targetStr1 : repStr1, targetStr2 : repStr2, ...})

template : テンプレートオブジェクト
targetStr1〜 : テンプレート文字列
repStr1〜 : 置換データ

説明

テンプレートに従って処理するにはevaluate()を使います。パラメータはハッシュ(連想配列)形式で指定します。キーがテンプレート名、値が実際に置き換える内容になります。複数ある場合にはカンマ(,)で区切って列記することができます。

サンプルコード [実行]

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<link rel="stylesheet" href="main.css" type="text/css" media="all">
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript"><!--
window.onload = function(){
var text = "今日の天気は#{weather}です。最高気温は#{temp}です。";
var template = new Template(text);
$("result").innerHTML = template.evaluate({
weather : "くもり",
temp : "13℃"
});
}
// --></script>
</head>
<body>
<h1>テンプレートに従って処理する</h1>
<div id="result"></div>
</body>
</html>