官术网_书友最值得收藏!

How to do it...

  1. In workspace/app, add a new folder and call it partial:
      cd && cd worspace/app && mkdir partial
  1. Add _nav.ejs to the partial folder--touch partial/_nav.ejs.
  2. Open the app/index.html and cut all the code starting with <nav> and ending with </nav> (the whole navbar). Paste the code into the _nav.ejs file.
  3. In index.html, right where you cut out the <nav> element, paste this include:
      <%- partial("partial/_nav") %>
  1. Make a new file, _data.json, in workspace/app:
      touch _data.json
  1. Paste the following code into it:
      { 
"index": {
"title": "Welcome to Our Homepage"
},
"about": {
"title": "About Us"
}
}
Note that "index" is the name of the file ( index.html), and "title" is the text for the <title> tag of the index page. We can add more pages as needed.
  1. Now, let's copy and rename index.html to _layout.ejs:
      cp index.html _layout.ejs
  1. C9 into index.html and delete everything except the div with the class of container, that is, keep only the following code in index.html:
      <div class="container">

<div class="starter-template">
<h1>Bootstrap 4 Grid Recipe</h1>
<p class="lead">Use this document to quickly start any new
project.
<br> All you get is this text and a barebones HTML document.
</p>
</div>

</div><!-- /.container -->
  1. Change the file extension of index.html to index.ejs:
      mv index.html index.ejs
  1. In _layout.ejs, add the title of the current page:
      <title><%- title %></title>
  1. Also, delete everything under the _nav partial include, all the way up to the comment <!-- Bootstrap core JavaScript ... and place just this one line there:
      <%- yield %>
  1. Run the harp compile and harp server commands to verify that everything still works.

In this recipe, we have split our code into includes, making it a lot easier to work with. In the following recipes, we will deal with layouts.

Do not forget to change the variable overrides in the  main.scss file if you want your recipe code to have a nice background color and your navbar to have regular-sized text.
主站蜘蛛池模板: 聂拉木县| 舒兰市| 三台县| 台南市| 尼木县| 巴林左旗| 民县| 云阳县| 灯塔市| 饶平县| 徐水县| 德江县| 贡山| 抚宁县| 偃师市| 永定县| 汶川县| 华宁县| 永胜县| 府谷县| 高碑店市| 淮安市| 永泰县| 滁州市| 绍兴县| 明溪县| 崇礼县| 荔波县| 永平县| 霞浦县| 大港区| 宜川县| 金沙县| 济南市| 阿拉善盟| 尼木县| 囊谦县| 盐津县| 龙游县| 桐城市| 汝州市|