LoginSignup
1

More than 5 years have passed since last update.

mustache.js cli で {{> head}} 形式のパーシャルテンプレート読み込みする方法

Posted at

mustache.js cli で {{> head}} 形式のパーシャルテンプレート読み込みする方法

npm install mustache などで mustache をいれて、

<html>
 {{> header.html}}
<body>
 本文
 {{> footer.html}}
</body>
</html>

こういう html で、

#ls

template.mustache header.html footer.html

ファイルがこうあって、

# mustache var.json template.mustache

上記のように実行しても {{> header.html}} はまったく解決してくれない。

ソース見ると -p でファイル名をすべて指定する必要があり、かつ、{{> }} ではファイル名から mustache をのぞいた名前を期待してるようだったので

<html>
 {{> header}}
<body>
 本文
 {{> footer}}
</body>
</html>

こういう html で、

#ls

template.mustache header.mustache footer.mustache

ファイル名の拡張子を mustache にして

# mustache var.json template.html -p header.mustache -p footer.mustache

のように渡せばうまくいきました。

また、サブディレクトリ配下においていも、basename を取られるので、 {{> partial/header}} とかは上手くいかない。

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
1