メインコンテンツまでスキップ

インクルード

include、include head、head、include foot、foot

説明

{{ include 'foo/bar' }}
{{ include head 'foo/bar' }}
{{ head }}
{{ include foot 'foo/bar' }}
{{ foot }}

別のテンプレートをインクルードします。

{{ include }}はテンプレートを読み込み、記述された場所に表示しますが、{{ include head }}{{ include foot }}はテンプレートを読み込み、{{ head }}{{ foot }}の位置に表示します。

テンプレート - child.tpl
<p>このファイルはchild.tplです</p>
テンプレート - parent.tpl
<p>このファイルはparent.tplです</p>
{{ include 'parts' }}
出力
<p>このファイルはchild.tplです</p>
<p>このファイルはparent.tplです</p>

{{ include head }}{{ include foot }}を使用する場合。

テンプレート - header.tpl
<link rel="stylesheet" type="text/css" href="path/to/style.css">
テンプレート - footer.tpl
<script type="text/javascript" src="path/to/script.js"></script>
テンプレート - parent.tpl
{{ include head 'header' }}
{{ include foot 'footer' }}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ページタイトル</title>

{{ head }}

</head>
<body>
何かの内容

{{ foot }}

</body>
</html>
出力
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ページタイトル</title>

<link rel="stylesheet" type="text/css" href="path/to/style.css">

</head>
<body>
何かの内容

<script type="text/javascript" src="path/to/script.js"></script>

</body>
</html>