tutorial04.rst 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. Tutorial Part 4: Navbar & Footer
  2. ================================
  3. While CRX comes with a very rudimentary Navbar and Footer, the ``pro`` project template comes with a more realistic customizable Navbar and Footer in your local project. In this guide, we will look at how to customize the ``pro`` Navbar and Footer.
  4. .. _navbar:
  5. Navbar and Footer Source Code
  6. -----------------------------
  7. Your project has a custom implemented navbar and footer, the associated files are:
  8. * Wagtail snippets at bottom of ``website/models.py``
  9. * Starting point: ``website/templates/coderedcms/snippets/navbar.html`` and ``footer.html``. These override the built-in navbar and footer from CRX, and will therefore be present on all pages automatically.
  10. * A few custom blocks in: ``website/templates/website/blocks/navbar_link.html`` and ``navbar_dropdown.html``.
  11. Create your Navbar
  12. ------------------
  13. Your navbar will have links to your other pages or external content that you want
  14. to share. To build your Navbar, go to **Snippets > Navigation Bars**.
  15. There is a button in the top right corner named **Add Navigation Bar**.
  16. Click on this button to start! (Alternatively, you can also click on the link that says "Why not add one?")
  17. Giving the navbar a name is required. Also note, as you use different editing interfaces in Wagtail, required fields are marked with a red asterisk (*).
  18. Since, this will be a site wide navigation bar we have named it Main Nav Bar.
  19. * The **Link** blocks are the ``NavbarLinkBlock`` defined in ``website/models.py``.
  20. * The **Dropdown** block is defined in ``NavbarDropdown`` in ``website/models.py``.
  21. * You can see from looking at the ``Navbar`` snippet in ``website/models.py``, that it is defining fields with StreamBlocks of these.
  22. Let's add **Links** to our navigation bar.
  23. * Click "choose page" and link to "Home"
  24. * Add another by selecting the "+" at the bottom of the page.
  25. * Click "choose page" and link to "About Us"
  26. * Add another by selecting the "+" at the bottom of the page.
  27. * Click "choose page" and link to "Our Products"
  28. * Add another by selecting the "+" at the bottom of the page.
  29. * Click "choose page" and link to "Contact Us"
  30. * **Save**
  31. The new navbar will now automatically be loaded into the ``website/templates/coderedcms/snippets/navbar.html`` by calling the ``get_website_navbars`` template tag defined in: ``website/templatetags/website_tags.py``.
  32. .. _footer:
  33. Customizing the Footer
  34. ----------------------
  35. Let's work on the footer, which is another menu of links. You can add more links in the footer
  36. that maybe won't belong in the main navigation but are still important. Go to **Snippets > Footers** to begin
  37. working on the footer. In the top right-hand corner is a button that says **Add Footer**. Click on this button to start!
  38. (Alternatively, you can also click on the link that says "Why not add one?")
  39. Give your footer a name. We chose Main Footer since this will be the main footer for our site.
  40. Let's get some practice with Responsive Grid Rows and Columns! We want to make a 4-column footer with sub-page links in the first column,
  41. external links to social media in the second, an address in the third, and links for legal disclosures in the last column.
  42. .. note::
  43. To keep up with our design, we have also added a few Bootstrap classes to our footer. In the Custom CSS Class field, add "bg-secondary text-white".
  44. This will change the footer's background color to the green we set in Part 01 and uses a built in Bootstrap class to make the text white.
  45. To set up our 4-column footer:
  46. * Choose **Responsive Grid Row** from the layout choices at the bottom.
  47. * Click on **Add Column**. You can specify the column size in the dropdown that says **Column size**.
  48. * Choose a 1/4 Column size for all 4 columns.
  49. .. note::
  50. Bootstrap uses a 12-column grid, and our footer is going to span the entire 12 columns. To figure out
  51. how to size our columns, we do some math. We are slicing up the 12-column grid into fourths to have four columns,
  52. so our columns need to be 1/4 each. Read more about Bootstrap grids and columns here: `Bootstrap Grid <https://getbootstrap.com/docs/4.0/layout/grid/>`_.
  53. From within the Responsive Grid Row block, keep selecting the + sign below your **Column** until you have all of
  54. the columns that you need. Then remember to make sure to choose the size of the column. Otherwise, it will automatically size on its own.
  55. Add Content to the Footer
  56. -------------------------
  57. Now that we have our layout, let's begin adding content! You see that there are several different choices for content
  58. available within the column block.
  59. We will be using a text block in all 4 columns. In the first column's text block:
  60. * Enter "Short Cuts:" and hit enter to make a new line (alternatively you can click the right angled arrow to get a new line.)
  61. * Click on the chain link symbol which should bring up this screen:
  62. .. figure:: images/tut04/choose_a_page.jpeg
  63. :alt: Link editing screen
  64. Link editing screen.
  65. * Choose "What's New at CRX-Pharma" page
  66. * Do this a few more times choosing the "Careers", "Our Products", "Contact Us" pages.
  67. For the second column's text block:
  68. * Enter "Social Media:" and hit enter to make a new line.
  69. * Click on the chain link symbol which should bring up the link modal.
  70. * Click **External Link**
  71. * Enter "www.facebook.com" in the URL field.
  72. * Enter "Facebook" in the Link text field.
  73. * Click **Insert link**
  74. * Do this a few more times for other Social Media sites, such as twitter, linkedIn, and Instagram
  75. For the third column's text block:
  76. * Enter "Address:" and hit enter to make a new line.
  77. * Enter an address (format it to your liking)
  78. * Click on the chain link symbol which should bring up the link modal.
  79. * Click **Phone Link**
  80. * Enter a Phone number in the field and leave the other blank, click **Insert link**.
  81. * Click on the chain link symbol which should bring up the link modal.
  82. * Click **Email Link**
  83. * Enter an Email address in that field and "Email Us" in the Link text, click **Insert link**.
  84. For the fourth column's text block let's add a document link.
  85. Here's a fake legal disclosure we can use: :download:`fake legal pdf <images/tut04/CRXPharmaFakeLegal.pdf>`.
  86. Download that file. Remember it's location on your computer. In the fourth column's text editor:
  87. * Enter "Legal:" and hit enter to make a new line.
  88. * Choose document (next to the chain link)
  89. .. figure:: images/tut04/document_link.jpeg
  90. :alt: Text editor with document link highlighted
  91. Text editor with document link highlighted
  92. * This opens the document management modal
  93. .. figure:: images/tut04/document_modal.jpeg
  94. :alt: document management modal
  95. document management modal
  96. * Select the Upload Tab
  97. * Choose the file provided above.
  98. * Change the Title to "Privacy Policy"
  99. .. figure:: images/tut04/document_pp.jpeg
  100. :alt: document management modal with document selected
  101. document management modal with document selected
  102. * Select Upload.
  103. * And now you see the document link in your text editor.
  104. * For the rest of the legal section, we are going use placeholder text (meaning no links). We put a line for Terms of Use, and Disclosures
  105. Our Editing Page:
  106. .. figure:: images/tut04/footer_edit.jpeg
  107. :alt: Footer Editing Page
  108. Footer Editing Page
  109. Once you're happy with your Footer, hit **Save**. Let's see what it looks like!
  110. Let's change the Bootstrap default blue links by adding custom CSS to give it a nicer look.
  111. * In your file explorer go to **mysite>website>static>website>src>custom.scss**
  112. * Add the following code under *// Add your custom styles here.* (line 26) :
  113. .. code-block::
  114. .secondary-links {
  115. a {
  116. color: $white;
  117. text-decoration: none;
  118. }
  119. a:hover {
  120. color: $dark;
  121. }
  122. }
  123. Our custom.scss now looks like this:
  124. .. figure:: images/tut04/secondary_links.jpg
  125. :alt: custom.scss file with secondary link class added
  126. custom.scss file with secondary link class added
  127. Remember to compile your sass:
  128. * Stop your server with `ctrl + c`.
  129. * Run:
  130. .. code-block:: console
  131. $ python manage.py sass website/static/website/src/custom.scss website/static/website/css/custom.css
  132. * Restart server with `python manage.py runserver`
  133. * Go to back to **Snippets > Footers**
  134. * Edit "Main Footer"
  135. * Add "secondary-links" the new css class along side "bg-secondary text-white" in the Custom CSS Class field.
  136. .. figure:: images/tut04/adding_sec_links.jpeg
  137. :alt: secondary-link class added to Custom CSS Class field
  138. secondary-link class added to Custom CSS Class field
  139. * **Save**
  140. * Navigate to the Home page at http://localhost:8000/
  141. * Be sure to hard refresh and load the current CSS stylesheet.
  142. .. figure:: images/tut04/footer_style.jpeg
  143. :alt: footer with new class secondary-link class
  144. footer with new class secondary-link class
  145. Take a moment to hover over the link text and see it changes color. Now the homepage is starting to feel like a
  146. professional site.
  147. .. figure:: images/tut04/homepage_finished.jpeg
  148. :alt: The homepage with navbar and footer
  149. The homepage with navbar and footer
  150. Now let's look at building a blog landing page and blog pages.