Unit 02 · lesson
Loops and Generated Lists
One of the best reasons to use a static site generator is to stop hand-copying repeated markup.
Loops let one template render many items from structured data.
Basic Liquid loop
<ul>
{% for skill in page.skills %}
<li>{{ skill }}</li>
{% endfor %}
</ul>
Front matter:
skills:
- Python
- Linux
- Robotics
Jekyll can generate three list items from one template.
Trace the mechanism
YAML LIST
↓ page.skills
LIQUID LOOP
↓ one iteration per item
HTML LIST ITEMS
Inspect _site and count the generated <li> elements.
Controlled change
Add one skill to YAML.
Predict:
- which source file changes;
- which template stays unchanged;
- how many output list items should exist after the build.
Build and verify.
That is the maintainability win: content changes without duplicating markup logic.
Empty lists
What if skills is empty or missing?
Test it.
Then decide whether your template should:
- show nothing;
- show a fallback message; or
- enforce that the data must exist.
Different sites can make different decisions. The important part is making the behavior deliberate.
Portfolio action
Use a loop to generate one real repeated element from data you own.
Good candidates:
- skills;
- current tools;
- interests;
- project technologies.
Unit 4 will move larger repeated datasets into _data and collections.
Checkpoint
Explain why this:
{% for skill in page.skills %}
can be easier to maintain than copying five <li> blocks by hand.
Your answer should mention separation of data from rendering structure.