tutorial03.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. Tutorial Part 3: Adding Content, Custom CSS
  2. ===========================================
  3. Now let's start adding some content to our site.
  4. Adding a hero unit to the home page
  5. -----------------------------------
  6. In the admin dashboard, select **Pages >**. This will open a tree-style view of all the pages
  7. on our site. You will see all the pages we added. Click the pencil icon to edit the home page, or click
  8. "Home" and then the "Edit" button.
  9. Here in the body section is where we can add our content. Each component in this section is called
  10. a "block" and provides a different format of content. Wagtail CRX is heavily based on Bootstrap CSS
  11. and its grid system, which means all content is based in rows and columns that dynamically stack depending
  12. on the visitor's screen size. `Read more here. <https://getbootstrap.com/docs/5.2/layout/grid/>`_
  13. First, let's make a big flashy hero unit. A hero unit in Wagtail CRX is a block that allows for
  14. a full-width background image or background color, and has lots of padding by default.
  15. * Select the **Hero Unit** block.
  16. * Be sure full-width is selected. (It should be selected by default when using a Hero Unit block)
  17. * Next set a background image - we are going to download and use `this laboratory image <https://pixabay.com/photos/laboratory-analysis-chemistry-2815641/>`_ from `Pixabay <https://pixabay.com>`_.
  18. * Enter "white" in the Text color field
  19. Let's add content to our hero unit. Under the **Content** field:
  20. * Select **Responsive Grid Row**
  21. * Select **Column**. Inside our column,
  22. * Add **Text** block
  23. * Enter "Building a Healthier World" as an H2 in bold.
  24. * Enter "Research. Discovery. Manufacturing." as an H4 in italics in the same text editor.
  25. Next, click the small "+" icon directly below the text field. This will let you add another block
  26. directly below the text, but still in the same column.
  27. * Select the **Button Link** block. There are a few options here.
  28. * Choose **Page Link** and link it to "What's Happening at CRX-Pharma" page.
  29. * Change the **Button Title** field to "Read Our Blog"
  30. * Change the **Button Size** to large.
  31. My editing page now looks like this:
  32. .. figure:: images/tut03/hero_unit_editor.jpeg
  33. :alt: The home page editor after adding a hero unit.
  34. The home page editor after adding a hero unit.
  35. Next click **Save draft** and then **Preview** button at the bottom, which will open up a preview of the home page in a new tab.
  36. Great success!
  37. .. figure:: images/tut03/hero_unit.jpeg
  38. :alt: The home page preview after adding a hero unit.
  39. The home page preview after adding a hero unit.
  40. .. _custom_css:
  41. Custom CSS
  42. ----------
  43. You may have noticed a few issues with our page. The white text in our hero is a little hard to read and the search input is light teal.
  44. Let's add text-shadow to the hero text with our own custom CSS class. This will make the text stand out from the backdrop. We will also change how we are giving the body a background-color.
  45. * In your file explorer go to *mysite>website>static>website>src>custom.scss*
  46. * Add the following code under *// Add your custom styles here.* (line 26) :
  47. .. code-block::
  48. .text-shadow {
  49. text-shadow: $dark 1px 1px 12px;
  50. }
  51. * We will also add this :
  52. .. code-block::
  53. body {
  54. background-color: #a4f1e9;
  55. }
  56. Using the HTML body tag is another way to alter the background color of the site.
  57. Our custom.scss file after adding the above code:
  58. .. figure:: images/tut03/custom_css_inVScode.jpg
  59. :alt: custom.scss after adding custom classes.
  60. custom.scss after adding custom classes. Be sure to save this file!
  61. * Next we will remove or comment out the global body color $bg-body (line 36) in the *mysite>website>static>website>src>_variables.scss* file
  62. because it's changing the background-color of the inputs. Our newly added css will now change the background-color of the body.
  63. .. figure:: images/tut03/body_commented_out.jpg
  64. :alt: $bg-body commented out.
  65. $bg-body commented out in mysite>website>static>website>src>_variables.scss. Be sure to save this file!
  66. * Compile the sass. In your terminal:
  67. * Stop your server with `ctrl + c`.
  68. * Run:
  69. .. code-block:: console
  70. $ python manage.py sass website/static/website/src/custom.scss website/static/website/css/custom.css
  71. * Restart server with `python manage.py runserver`
  72. * Hard refresh your web browser
  73. Lets use the *text-shadow* class we just made.
  74. * Back to the home page editor screen, in the column block, click **Advanced Settings**
  75. * Enter "text-shadow" in the Custom CSS Class field. See below :
  76. .. figure:: images/tut03/custom_css.jpeg
  77. :alt: adding custom CSS
  78. Adding a custom class
  79. * **Save** and **Publish**
  80. .. figure:: images/tut03/hero_unit_shadow.jpeg
  81. :alt: Hero with shadow
  82. The hero unit with text shadow and the search input background no longer is light teal.
  83. Awesome. The inputs are no longer have the light teal background and our text in the Hero Unit has a shadow that makes it stand out from the backdrop.
  84. Adding cards to the home page
  85. -----------------------------
  86. .. note::
  87. We used these images from pixabay in our cards. You'll need to download them.
  88. * `stethoscope <https://pixabay.com/photos/blood-pressure-stethoscope-medical-1584223/>`_
  89. * `lab equipment <https://pixabay.com/photos/laboratory-apparatus-equipment-217041/>`_
  90. * `colorful brain <https://pixabay.com/illustrations/brain-mind-psychology-idea-drawing-2062057/>`_
  91. Let's add three cards to highlight CRX-pharma's strengths. Go back to the tab with the home page editor.
  92. All the way at the bottom of the page, click the "+" icon directly below the "Hero Unit" block.
  93. This will add a new block directly below the hero unit.
  94. * Select the **Card Grid** block.
  95. * Select **Card** to add the first card.
  96. * Add an image (stethoscope)
  97. * Fill out the **Title** with "Industry Leader in Innovations"
  98. * Fill out the **Body** with a few sentences of text
  99. * Add a **Button Link** at the bottom
  100. * Use **Page Link** and link it to the "About Us" page created in Part 2
  101. * Fill out **Button Title** with "Our History"
  102. Next add and fill out two more cards by scrolling down and clicking the "+" icon directly below our current card block.
  103. The second card should have:
  104. * An image (lab equipment)
  105. * **Title** "Unparalleled Manufacturing"
  106. * **Body** with a few sentences of text
  107. * **Button Link** with:
  108. * **Page Link** to "Our Facility" Page
  109. * **Button Title** "Our Facility"
  110. The third card should have:
  111. * An image (colorful brain)
  112. * **Title** "Our Philosophy"
  113. * **Body** with a few sentences of text
  114. * **Button Link** with:
  115. * **Page Link** to "Our Products" Page
  116. * **Button Title** "Shop With Us"
  117. The editing page now looks like this:
  118. .. figure:: images/tut03/cards_1.jpeg
  119. :alt: The home page editor after adding a card grid with three cards 1 of 2.
  120. The home page editor after adding a card grid with three cards 1 of 2.
  121. .. figure:: images/tut03/cards_2.jpeg
  122. :alt: The home page editor after adding a card grid with three cards 2 of 2.
  123. The home page editor after adding a card grid with three cards 2 of 2.
  124. **Save draft** and click the **Preview** button at the bottom, which will open up a preview of the home page in a new tab.
  125. Lookin' good!
  126. .. figure:: images/tut03/card_preview.jpeg
  127. :alt: The home page preview after adding the card grid.
  128. The home page preview after adding the card grid.
  129. .. note::
  130. At this point you may notice that the cards aren't the same height. You can fix this two ways. One you can add the bootstrap
  131. CSS class of h-100 to each card, two you can add `$card-height: 100%` in the _variables.scss. If you use the sass option remember to compile the sass files.
  132. This is the most basic use case of card-grid check out :ref:`card-grid` for more information.
  133. To make all the cards equal height, We added bootstrap class h-100 to each card as seen here:
  134. .. figure:: images/tut03/h_100.jpeg
  135. :alt: card block with custom class of h-100
  136. Card block with custom class of h-100. Be sure to do this to each card.
  137. .. figure:: images/tut03/card_preview_h100.jpeg
  138. :alt: The home page preview with the same size cards.
  139. The home page preview with the same size cards.
  140. .. note::
  141. Check out these resource for cards: :ref:`card-grid` and :ref:`card-block`.
  142. Adding more content to the home page
  143. ------------------------------------
  144. We'll continue following this pattern to add content. While the **Hero Unit** and **Card Grid** provide
  145. "special" content formats, the **Responsive Grid Row** is the most general purpose block for adding content. There is also an
  146. **HTML** block for inserting raw HTML if needed.
  147. Let's look at **Responsive Grid Row** in practice.
  148. * Add a **Responsive Grid Row** below our **Card Grid**
  149. * Select **Column**
  150. * Change **Column size** to "Half - 1/2 column"
  151. * Select **Text**
  152. * Enter "Our Products" and make it an H2.
  153. * Enter a few sentences of text under the "Our Products" in the same text editor.
  154. * Add a **Button link** linked to the "Direct to Consumer". (child of Our Products). Be sure to give a Title.
  155. * Add a **Button link** linked to the "Bulk Sales". (child of Our Products). Be sure to give a Title.
  156. * Below the Column Block (second to last "+") Add another **Column**
  157. * Change **Column size** to "Half - 1/2 column"
  158. * Add an **Image** We used `this one <https://pixabay.com/photos/medications-tablets-medicine-cure-1853400/>`_
  159. .. figure:: images/tut03/our_products_editing.jpeg
  160. :alt: Our Products editing Page
  161. Our Products editing Page.
  162. * **Save** and **Preview**
  163. .. figure:: images/tut03/our_products_preview.jpeg
  164. :alt: Our Products preview Page
  165. Home Page with Our Products added.
  166. We are going to do another **Responsive Grid Row**
  167. * Add another Responsive Grid Row
  168. * Add a Column set it to 1/2 column with this `image <https://pixabay.com/photos/building-hospital-white-modern-2654823/>`_
  169. * Add a Column set it to 1/2 column add text for Our Facility
  170. * Add a Button Link under the text block that is linked to Our Facility.
  171. * **Save** and **Preview**
  172. .. figure:: images/tut03/our_facility.jpeg
  173. :alt: Home Page with Our Facility added.
  174. Home Page with Our Facility added
  175. For the Last two **Responsive Grid Rows** reference the last image on this page as a guide.
  176. Follow these links to get the images. (note: I cropped my images square using a photo editor):
  177. * `doctor 1 <https://pixabay.com/photos/doctor-gray-hair-experience-2337835/>`_
  178. * `doctor 2 <https://pixabay.com/photos/woman-doctor-surgeon-physician-2141808/>`_
  179. To get the green background, white text, and proper padding you will want to add "bg-secondary text-white p-5"
  180. in the Custom CSS field on each column with text. These are bootstrap classes that come pre-loaded in Wagtail-CRX.
  181. When we set the secondary color to green in part 01 of the tutorial, we made all the bootstrap classes that have "secondary" in the class name
  182. reference that color. This screenshot shows how to add these classes to the column. You must open advanced settings on the column:
  183. .. figure:: images/tut03/custom_classes.jpeg
  184. :alt: bootstrap classes on columns
  185. Bootstrap classes on columns
  186. Hopefully you were able to follow along and your page looks like this:
  187. .. figure:: images/tut03/home_page_finished.jpeg
  188. :alt: home page after tutorial part 3
  189. home page after tutorial part 3 (note: the images of the doctors were cropped to be square)
  190. Next we will look at building a Navbar and Footer.