Harp 全局變量

2021-10-12 15:49 更新

概述

全局變量是存儲(chǔ)在 harp.json 文件中的 JSON 數(shù)據(jù),對(duì)所有的頁(yè)面、模板、局部視圖以及布局文件可用。

Harp 不僅僅只是靜態(tài)文件,頁(yè)面也可以通過動(dòng)態(tài)內(nèi)容創(chuàng)建。像全局屬性中添加內(nèi)容是天生可取的。

harp.json

{
  "globals": {
    "title": "Acme Site",
    "name"  : "John Doe",
    "uri": "http://example.com"
  }
}

Jade 示例

index.jade

html
  head
    title #{ title }
  body
    h1 Hello #{ name }!

EJS 示例

index.ejs

<html>
  <head>
    <title><%= title %></title>
  </head>
  <body>
    <h1>Hello <%= name %>!</h1>
  </body>
</html>


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)