1

I have a website which contains a navbar with various options and a footer, I want to include the navbar and footer in different file so that I can use when in all other webpages. I am using Flask in development

This is my code for navbar

<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
  <!-- Brand -->
  <a class="navbar-brand" href="#"> SpiritUs</a>



  <!-- Links -->

      <ul class="navbar-nav">

    <!-- Dropdown -->
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
        Beer
      </a>
      <div class="dropdown-menu">
        <a class="dropdown-item" href="{{ url_for('indianBeer') }}">Indian Beer</a>
        <a class="dropdown-item" href="{{ url_for('importedBeer') }}">Imported Beer</a>

      </div>
    </li>
</ul>
</nav>

This is my footer

<div class="Footer">
        <div class="container">
            <div class="row centered">
                    <h4 style="text-transform:uppercase;"><em>
                    <span style="border-bottom: 2px solid #dd7700;"> Get your favourite liquior at your doorstep! </span>
                    <span style="border-bottom: 2px solid #dd2210;"> Contact Us</span>
                    </em></h4>

                    <p><strong>&copy; Mahin Malhotra, Kunal Sharma and Anshu Bansal</strong></p>

                    <a href="https://twitter.com" target="_blank"><i class="fa fa-twitter"></i></a>
                    <a href="https://facebook.com" target="_blank"><i class="fa fa-facebook"></i></a>

            </div><!-- row -->
        </div><!-- container -->
    </div><!-- Footer -->
Turnip
  • 35,836
  • 15
  • 89
  • 111
  • You could work with php include. Save footer and header in a seperate php file and the inlcude the footer.php and header.php in your needed files. – Kuba Mar 27 '18 at 09:32
  • There aren't many good options for having the header and footer in separate files on the client side. I'm not familiar with Flask or Jinja2 but if you have PHP, use `include` to get your header and footer from separate files. Other solutions work for other languages too. – spacer GIF Mar 27 '18 at 09:32
  • Apart from php? –  Mar 27 '18 at 09:32
  • 2
    Have you seen this? https://stackoverflow.com/questions/9679038/is-it-possible-to-perform-includes-with-flask – Turnip Mar 27 '18 at 09:33
  • @MahinMalhotra If you're using Microsoft stuff on your server, it has its own equivalent of PHP's `include`, but if you look at Turnip's link it seems that Flask has its own one too. – spacer GIF Mar 27 '18 at 09:36
  • Thanks for the help ! will implement this soon –  Mar 27 '18 at 10:00

0 Answers0