Frontend environment object

2019-01-07 05:47:08

In order to facilitate the flexible and rich functional logic of the frontend, some environmental parameters need to be injected into the frontend.

Cabloy-CMS itself has some built-in environment objects. Meanwhile, you can also inject custom properties through env of the backend context object. These parameters will be merged and then injected into the frontend.

Inject ENV

env('index',{
  [_path]:data.index,
});

Placeholder

/ ENV placeholder
_ _ENV_ _

Frontend environment object structure

<script type="text/javascript">
var env={
  "base": {
    "title": "my blog",
    "subTitle": "gone with the wind",
    "description": "",
    "keywords": ""
  },
  "language": {
    "items": "en-us,zh-cn",
    "default": "en-us",
    "current": "en-us"
  },
  "format": {
    "date": "YYYY-MM-DD",
    "time": "HH:mm:ss"
  },
  "comment": {
    "order": "asc",
    "recentNum": 5
  },
  "site": {
    "path": "main/article",
    "serverUrl": "https://zhennann.cabloy.org",
    "rawRootUrl": "https://zhennann.me"
  },
  "article": ...,
  "index": {
    "main/index/index": 20
  }
};
</script>
Name Source Instruction
base Site configuration Site basic information
language Site configuration Language information
format Site configuration Time formatting
comment Site configuration Comment parameter
site Built-in parameters Site parameter
site.path Path indication of current page
site.serverUrl URL prefix of backend service
site.rawRootUrl URL prefix of frontend site
article Built-in parameter If it is an article page, this property is automatically injected.
index Custom parameter Parameters injected by the theme cms-themeblog


Comments: