LoginSignup
16
15

More than 5 years have passed since last update.

静的ページを作るときに助かるJadeでtemplateに変数を渡す方法

Last updated at Posted at 2014-07-17

Jadeを使う場合はexpress.jsのテンプレートエンジンとして
使うことがほとんどだと思いますが。

静的ページ作成にも速攻で作れるのでとても便利です。

ただ静的ページを作る場合gulpとかで
localsで各ページ共通の変数を渡すのはいいんですが

各ページごとに変数を変えたい場合どうすればいいんだろうなと思い調べました。

layout.jade
//- headやbodyは省略してます。
doctype html
block vars
meta(charset="UTF-8")
title= title
h1= title
block contents
cheese.jade
extends layout

block vars
  - var title = "Cheese Official Page"

block contents
  p Welcome to Cheese Paradise!!
corgi.jade
extends layout

block vars
  - var title = "Corgi Official Page"

block contents
  p Welcome to Corgi Paradise!!

blockを作り継承先のjadeのblockに変数を入れてあげればいいみたいです。

16
15
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
16
15