You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/customization.qmd
+91-8Lines changed: 91 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -117,18 +117,100 @@ To generate the HTML pages to be returned from our GET routes, we use Jinja2 tem
117
117
118
118
With Jinja2, we can use the `{% block %}` tag to define content blocks, and the `{% extends %}` tag to extend a base template. We can also use the `{% include %}` tag to include a component in a parent template. See the [Jinja2 documentation on template inheritance](https://jinja.palletsprojects.com/en/stable/templates/#template-inheritance) for more details.
119
119
120
-
### Bootstrap Sass Files
121
-
Install Node.js on your local machine if it is not there already.
122
-
Install sass, gulp, and gulp-sass on your local machine:
120
+
### Custom theming with Bootstrap Sass
121
+
122
+
[Install Node.js](https://nodejs.org/en/download/) on your local machine if it is not there already.
123
+
124
+
Install `bootstrap`, `sass`, `gulp`, and `gulp-sass` in your project:
This will create a `node_modules` folder, a `package-lock.json` file, and a `package.json` file in the root directory of the project.
131
+
132
+
Create an `scss` folder and a basic `scss/styles.scss` file:
133
+
123
134
```bash
124
-
npm install sass gulp gulp-sass
135
+
mkdir scss
136
+
touch scss/styles.scss
137
+
```
138
+
139
+
Your custom styles will go in `scss/styles.scss`, along with `@import` statements to include the Bootstrap components you want. For example, the default CSS for the template was compiled from the following configuration, which imports all of Bootstrap and overrides the `$theme-colors` and `$font-family-base` variables:
140
+
141
+
```scss
142
+
// styles.scss
143
+
144
+
// Include any default variable overrides here (functions won't be available)
Restart VS Code and press Run Task from the Terminal menu on the gulpfile.js. Choose gulp:default and select your option for output. This automates Sass compilation.
127
187
128
-
There is already a default styles.scss file in the `scss` folder. Here are customization instructions for Sass files that can be included in `sass`:
129
-
[Boostrap Customization with Sass](https://getbootstrap.com/docs/5.3/customize/sass/)
188
+
The most common use case for `styles.scss` is to define a custom color scheme and fonts, but it's also possible to other visual details such as border radius and box shadow depth. See the [Bootstrap Sass customization instructions](https://getbootstrap.com/docs/5.3/customize/sass/) and the many free templates available at [Start Bootstrap](https://startbootstrap.com) for examples.
130
189
131
-
There are a lot of free templates available online, such as on [Start Bootstrap]|[https://startbootstrap.com]
190
+
To compile the Sass files, we use `gulp`. In the project root directory, create a `gulpfile.js` file with the following content:
.pipe(gulp.dest('static/css')); // Destination folder for compiled CSS
201
+
});
202
+
203
+
// Define a default task
204
+
gulp.task('default', gulp.series('sass'));
205
+
```
206
+
207
+
To compile the Sass file to `static/css`, run this command:
208
+
209
+
```bash
210
+
npx gulp
211
+
```
212
+
213
+
Note that this will overwrite the existing `static/css/styles.css` file, so if you want to define any custom CSS styles, you should do so in either the `scss/styles.scss` file or in `static/css/extras.css`.
132
214
133
215
#### Context variables
134
216
@@ -150,6 +232,7 @@ In this example, the `welcome.html` template will receive two pieces of context:
150
232
While this template includes comprehensive server-side validation through Pydantic models and custom validators, it's important to note that server-side validation should be treated as a fallback security measure. If users ever see the `validation_error.html` template, it indicates that our client-side validation has failed to catch invalid input before it reaches the server.
151
233
152
234
Best practices dictate implementing thorough client-side validation via JavaScript and/or HTML `input` element `pattern` attributes to:
235
+
153
236
- Provide immediate feedback to users
154
237
- Reduce server load
155
238
- Improve user experience by avoiding round-trips to the server
0 commit comments