Node.js 6.x Blueprints
上QQ阅读APP看书,第一时间看更新

Creating the application templates/views

Now let's create the application views:

  1. Within the views/pages folder, create a new file called band-list.html and add the following code:
          {% extends 'layout.html' %} 
          {% block title %}{% endblock %} 
          {% block content %} 
          <div class="album text-muted"> 
          <div class="container"> 
          <div class="row"> 
                      {% for band in bands %} 
          <div class="card col-lg-4"> 
          <h2 class="text-lg-center">{{ band.name }}</h2> 
                              {% if band.album == null %} 
           <img src="https://placehold.it/320x320" alt="{{ band.name }}"
            style="height: 320px; width: 100%; display: block;"> 
                              {% endif %} 
                              {% if band.album %} 
           <img src="{{ band.album }}" width="100%" height="320px"> 
                              {% endif %} 
           <p class ="card-text">{{ band.description }}</p> 
           </div> 
                       {% endfor %} 
           </div> 
           </div> 
           </div> 
           {% endblock %} 
    
  2. Open views/pages/index.html and add the following code:
          {% extends 'layout.html' %} 
          {% block title %}{% endblock %} 
          {% block content %}  
          <section class="jumbotron text-xs-center"> 
          <div class="container"> 
            <h1 class="jumbotron-heading">{{ title }}</h1> 
            <p class="lead text-muted">{{ callToAction }}</p> 
            <p> 
            <a href="/bands" class="btn btn-secondary">
              View Full List Albums</a> 
            </p> 
          </div> 
          </section> 
          <div class="album text-muted"> 
            <div class="container"> 
              <div class="row"> 
                      {% for band in bands %} 
              <div class="card col-lg-4"> 
                <h2 class="text-lg-center">{{ band.name }}</h2> 
                              {% if band.album == null %} 
                <img src="https://placehold.it/320x320" alt="{{ band.name }}"
                  style="height: 320px; width: 100%; display: block;"> 
                          {% endif %} 
                          {% if band.album %} 
                <img src="{{ band.album }}" width="100%" height="320px"> 
                          {% endif %} 
                <p class="card-text">{{ band.description }}</p> 
              </div> 
                      {% endfor %} 
              </div> 
            </div> 
          </div> 
          {% endblock %} 
    
  3. Open views/pages/layou.html and add the following highlighted code:
          <!DOCTYPE html> 
          <html> 
          <head> 
              {% include "../partials/head.html" %} 
          </head> 
          <body>
     <div class="navbar-collapse inverse collapse" id="navbar-header" aria-expanded="false" style="height: 0px;"> <div class="container-fluid"> <div class="about"> <h4>About</h4> <p class="text-muted">Add some information about the album below, the author, or any other background context. Make it a few sentences long so folks can pick up some informative tidbits. Then, link them off to some social networking sites or contact information. </p> </div> <div class="social"> <h4>Contact</h4> <ul class="list-unstyled"> <li><a href="#">Follow on Twitter</a></li> <li><a href="#">Like on Facebook</a></li> <li><a href="#">Email me</a></li> </ul> </div> </div> </div> <div class="navbar navbar-static-top navbar-dark bg-inverse"> <div class="container-fluid"> <button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbar-header" aria-expanded="false"> </button> <a href="/" class="navbar-brand">MVC MySql App</a> </div> </div> 
     
                  {% block content %} 
                  {% endblock %} 
          <footer class="text-muted"> 
          <div class="container"> 
            <p class="pull-xs-right"> 
            <a href="#">Back to top</a>  
            </p> 
            <p>Sample Page using Album example from © Bootstrap!</p> 
            <p>New to Bootstrap? <a href="http://v4-alpha.getbootstrap.
                com/getting-started/introduction/">Visit the homepage
            </a>.</p> 
          </div> 
          </footer>
               {% include "../partials/footer.html" %} 
          </body> 
          </html>