* fix: add tests and steps * add necessary changes * edit for new boilerplate * fix: adjust content for boilerplate merge * add 4 passing 1 failing socketio * fix: add socketio changes * fix: update wording and http test Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com> * fix: replace glitch remix urls with repl.it urls * integrate steps between lessons 4 and 5 * add mongodb altas link * edit test to not require db deletion * correct register routing and formatting * fix typos and formatting * fix: typos, standardize spacing, and remove unnecessary hr elements * fix: add/update links Add or update Gist solution links at the bottom of each challenge. Also add a missing link/text to the top of one of the challenges. * fix: remove Repl.it/boilerplate repo links from all but first challenge * fix: add target='_blank' to links in challenges * add note about PIP browser issues * move PIP note to end of instructions Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com>
62 lines
2.5 KiB
Markdown
62 lines
2.5 KiB
Markdown
---
|
|
id: 5895f70bf9fc0f352b528e64
|
|
title: Use a Template Engine's Powers
|
|
challengeType: 2
|
|
forumTopicId: 301567
|
|
---
|
|
|
|
## Description
|
|
<section id='description'>
|
|
|
|
One of the greatest features of using a template engine is being able to pass variables from the server to the template file before rendering it to HTML.
|
|
|
|
In your Pug file, you're able to use a variable by referencing the variable name as <code>#{variable_name}</code> inline with other text on an element or by using an equal sign on the element without a space such as <code>p=variable_name</code> which assigns the variable's value to the p element's text.
|
|
|
|
We strongly recommend looking at the syntax and structure of Pug <a href='https://github.com/pugjs/pug' target='_blank'>here</a> on GitHub's README. Pug is all about using whitespace and tabs to show nested elements and cutting down on the amount of code needed to make a beautiful site.
|
|
|
|
Looking at our pug file 'index.pug' included in your project, we used the variables <em>title</em> and <em>message</em>.
|
|
|
|
To pass those along from our server, you will need to add an object as a second argument to your <em>res.render</em> with the variables and their values. For example, pass this object along setting the variables for your index view: <code>{title: 'Hello', message: 'Please login'}</code>
|
|
|
|
It should look like: <code>res.render(process.cwd() + '/views/pug/index', {title: 'Hello', message: 'Please login'});</code>
|
|
Now refresh your page and you should see those values rendered in your view in the correct spot as laid out in your index.pug file!
|
|
|
|
Submit your page when you think you've got it right. If you're running into errors, you can check out the project completed up to this point <a href='https://gist.github.com/camperbot/4af125119ed36e6e6a8bb920db0c0871' target='_blank'>here</a>.
|
|
|
|
</section>
|
|
|
|
## Instructions
|
|
<section id='instructions'>
|
|
|
|
</section>
|
|
|
|
## Tests
|
|
<section id='tests'>
|
|
|
|
```yml
|
|
tests:
|
|
- text: Pug should correctly render variables.
|
|
testString: getUserInput => $.get(getUserInput('url')+ '/') .then(data => { assert.match(data, /pug-variable("|')>Please login/gi, 'Your projects home page should now be rendered by pug with the projects .pug file unaltered'); }, xhr => { throw new Error(xhr.statusText); })
|
|
|
|
```
|
|
|
|
</section>
|
|
|
|
## Challenge Seed
|
|
<section id='challengeSeed'>
|
|
|
|
</section>
|
|
|
|
## Solution
|
|
<section id='solution'>
|
|
|
|
```js
|
|
/**
|
|
Backend challenges don't need solutions,
|
|
because they would need to be tested against a full working project.
|
|
Please check our contributing guidelines to learn more.
|
|
*/
|
|
```
|
|
|
|
</section>
|