- Bootstrap 4 Cookbook
- Ajdin Imsirovic
- 293字
- 2021-07-02 21:08:01
How to do it...
- In workspace/app, add a new folder and call it partial:
cd && cd worspace/app && mkdir partial
- Add _nav.ejs to the partial folder--touch partial/_nav.ejs.
- 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.
- In index.html, right where you cut out the <nav> element, paste this include:
<%- partial("partial/_nav") %>
- Make a new file, _data.json, in workspace/app:
touch _data.json
- 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.
- Now, let's copy and rename index.html to _layout.ejs:
cp index.html _layout.ejs
- 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 -->
- Change the file extension of index.html to index.ejs:
mv index.html index.ejs
- In _layout.ejs, add the title of the current page:
<title><%- title %></title>
- 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 %>
- 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.
推薦閱讀
- 演進式架構(原書第2版)
- AngularJS深度剖析與最佳實踐
- Raspberry Pi 2 Server Essentials
- Learning Network Forensics
- C語言程序設計同步訓練與上機指導(第三版)
- Spring Boot+MVC實戰指南
- ExtJS Web應用程序開發指南第2版
- Python第三方庫開發應用實戰
- 金融商業數據分析:基于Python和SAS
- Web前端測試與集成:Jasmine/Selenium/Protractor/Jenkins的最佳實踐
- Backbone.js Patterns and Best Practices
- Implementing Domain:Specific Languages with Xtext and Xtend
- PhantomJS Cookbook
- 前端程序員面試算法寶典
- Roslyn Cookbook