← All Lessons Student Walkthrough →

CiTi · Computer Coding · Year One · Unit 3

Text Variables: One Settings File for MySite

A lesson within “My First Website & Server-Side Management”

Program Computer Coding: Year 1
Unit 3: My First Website & Server-Side Management
Duration One class period (~55 min)
Grouping Individual, with pair “Break It” checks
Project MySite (adds includes/vars.inc)

Essential Question

From the Year 1 curriculum map
How do I manage large CSS projects? Can CSS be dynamic?

Last lesson, shared code moved into include files. Today the shared values move too. The full site path is typed once, as pathvar, in one settings file. The CSS, includes, and images paths are built from it, and every page and include reads them from there.

Curriculum Map Alignment

Verbatim from Yr 1 curriculum

Concept / Knowledge / Content: Web Tools

  • Identify issues related to website maintenance
  • Use templates and snippets to demonstrate efficient and consistent web site development
  • Compare and contrast client-side and server-side technologies

Skills / Tasks

Demonstrates understanding in:

Reusable Code Assets Code Type via Syntax Large Web Application Planning Dynamic CSS Management
Projects & Activities touched: Compartmental Navigation (from the Unit 3 Client Managed Business Web Project list)

Program Connections

Skills & Portrait alignment

Program Skills: What I’m Building Toward

Hands-On:

#3 Build and deliver a website from a client brief
#7 Validate and debug my own work

Professional:

#7 Treat a mistake as data, not failure
#9 Document as you go

NYS Portrait of a Graduate

Academically Prepared Critical Thinker Reflective and Future Focused

Guaranteed & Viable Curriculum Framework

3 Dimensions for this lesson

Integrated Academic Knowledge

Variables as named placeholders, the same idea as “let x = 5” in algebra. The difference between assigning a value and using it, and why order matters: a value must be assigned before any line that uses it.

Employability Skills

Every professional project keeps its settings in one configuration file so a change happens in one place. Commenting that file so a teammate (or future you) knows what each setting controls.

Technical Skills

Creating includes/vars.inc with WebDNA [text] variables, including it first on every page, replacing hard-coded values in header.inc, nav.inc, footer.inc, and the include lines with variables, giving each page its own title through a page-level variable, and debugging the common variable mistakes.

Learning Intention

“Unwrapped” from the standard

Students will understand that a variable stores a value under a name so it can be reused anywhere: and will build a vars.inc settings file for MySite so the site path, site name, and author live in one place, and every page shows its own title.

Success Criteria

  • I can explain what a variable is and why a website keeps its settings in one file.
  • I can create vars.inc with [text] variables for my paths (pathvar, cssvar, incvar, imgvar), site name, and author, and include it on the first line of every page.
  • I can use my variables in header.inc, nav.inc, footer.inc, and my include lines.
  • I can give each page its own browser-tab title by setting titlevar before the header include.
  • I can spot and fix the common variable mistakes: used before it is set, spaces around the =, a misspelled name, a tag name used as a variable name, and stray spaces in a value.

Authenticity Continuum

Where this lesson sits today
Instruction & Skill Practice
Teacher-Designed Simulation
Realistic Industry Task
Authentic Audience / Client
Product, Service, Impact, Solution

Students convert their own working site to a settings file, then run a “rebrand”: change the site name in one place and confirm it on every page. Push further: a classmate plays a client who requests a new site name and a new author credit by message; the developer makes the change in vars.inc only and replies with the live URL.

Materials & Prep

  • Students’ MySite with header.inc, nav.inc, and footer.inc working on every page, using full site paths (from the previous lesson)
  • Sublime Text, CyberDuck, and Chrome
  • Student Walkthrough (y1-u3-l5-so)
  • Teacher prep: confirm every student’s full site path, /citi/coding/2027/1/YOURINTS/mysite/ with their initials. It becomes the value of pathvar.
  • Demo site: Mr. Mac’s Magical Lego Tour is a finished MySite using every variable in this lesson. Its Break It demos are the same site broken on purpose, one mistake per page, each with an explanation box. Demo numbers are listed with each Tricky Part below.

How Variables Work

Set once, use anywhere

A WebDNA text variable has two parts: one tag that sets it and a second tag that uses it. Setting prints nothing. Using prints the stored value.

1. Set it (in vars.inc) Name, equals sign, value. No spaces around the =. [text]sitenamevar=Jordan's Lego Site[/text]
→
2. Use it (anywhere after) The variable name in square brackets. <h1>[sitenamevar]</h1>
→
3. The browser gets The value. The tag is gone. <h1>Jordan's Lego Site</h1>

The site path is the biggest win. In the last lesson students typed /citi/coding/2027/1/YOURINTS/mysite/ into every link, image, CSS link, and include line, often 20 or more times. After today it is typed once, as pathvar.

Variables built from variables

A value can use a variable that is already set. [text]cssvar=[pathvar]css/[/text] stores /citi/coding/2027/1/YOURINTS/mysite/css/. So pathvar is the base, and the CSS, includes, and images folders each get their own variable built from it. Two rules, both tested:

  • Base first. pathvar must be set above the lines that use it. If cssvar comes first, it stores the plain text [pathvar]css/ and the stylesheet link breaks.
  • The value is copied when it is set. Changing pathvar further down does not update cssvar. To move the site, edit the pathvar line itself.

Naming: end every variable in var

The class convention is lowercase names ending in var. It makes variables easy to spot in code ([cssvar] is clearly yours, [date] is clearly WebDNA’s), and it can never collide with a real WebDNA tag (see Tricky Part 4).

VariableValue (example)Used in
[pathvar]/citi/coding/2027/1/YOURINTS/mysite/Nav links; the base for the three below
[cssvar][pathvar]css/The stylesheet link in header.inc
[incvar][pathvar]includes/Every include line except vars.inc
[imgvar][pathvar]images/Every image
[sitenamevar]Jordan’s Lego Site<title>, header <h1>, footer, image alt text
[authorvar]Jordan DiazFooter copyright line
[titlevar]About MeSet on each page; used in the <title> inside header.inc

The Code

What students build

includes/vars.inc (new)

[!] MySite settings: change a value here and every page updates [/!] [!] pathvar is the base. The other paths are built from it, so it must come first. [/!] [text]pathvar=/citi/coding/2027/1/YOURINTS/mysite/[/text] [text]cssvar=[pathvar]css/[/text] [text]incvar=[pathvar]includes/[/text] [text]imgvar=[pathvar]images/[/text] [!] site info [/!] [text]sitenamevar=Jordan's Lego Site[/text] [text]authorvar=Jordan Diaz[/text]

One variable per line, pathvar first. Students only ever type their own path once, on the pathvar line; the three lines under it are the same for everyone. [!]...[/!] is a WebDNA comment: the server skips it, so it never shows up, not even in View Source.

Every page

[include file=/citi/coding/2027/1/YOURINTS/mysite/includes/vars.inc] [text]titlevar=About Me[/text] [include file=[incvar]header.inc] [include file=[incvar]nav.inc] <div class="bodycopy"> <div class="col-left"> <img src="[imgvar]me.jpg" alt="me"> </div> <div class="col-right"> body copy </div> </div> [include file=[incvar]footer.inc]

Line order matters. vars.inc comes first and is the only line that still spells out the full path: [incvar] does not exist until that file has been read. titlevar comes next, before the header include that uses it.

includes/header.inc

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>[titlevar] | [sitenamevar]</title> <link rel="stylesheet" href="[cssvar]style.css"> </head> <body> <div class="container"> <div class="header"> <img src="[imgvar]logo.jpg" alt="[sitenamevar] logo"> <h1>[sitenamevar]</h1> </div>

includes/nav.inc

<div class="nav"> <a href="[pathvar]">Home</a> <a href="[pathvar]about/">About</a> <a href="[pathvar]author/">Author</a> <a href="[pathvar]photos/">Photos</a> </div>

includes/footer.inc

<div class="footer"> <p>&copy; [date format=%Y] [authorvar] · [sitenamevar]</p> </div> </div> </body> </html>

Every path variable already ends with a /, so it is followed directly by the rest of the path: [cssvar]style.css, not [cssvar]/style.css.

The Tricky Parts

Break it on purpose

Every result below was tested on our WebDNA server. Each has a one-line experiment for the “Break It” phase: predict, test, then undo.

1Used before it is set

WebDNA reads a page top to bottom. A variable used before its [text] line prints as plain text, brackets and all: [titlevar] shows up in the browser tab. This is also why the vars.inc include line must spell out the full path: [incvar] is not set yet on that line.

Try it: move the [text]titlevar=...[/text] line below the header include. The tab shows [titlevar] | Jordan's Lego Site. Demo #1 ↗

2Spaces around the equals sign

[text]sitenamevar = Jordan's Lego Site[/text] looks fine but the space becomes part of the name, so [sitenamevar] was never set and prints as plain text. No error message appears. The rule: no spaces on either side of =.

Try it: add a space before the = on the sitenamevar line in vars.inc. Every page header shows [sitenamevar]. Demo #2 ↗

3Misspelled or never-set names

A typo like [sitnamevar] prints as plain text, exactly like any WebDNA tag the server does not recognize. Capital letters do not matter ([SiteNameVar] works), but the class convention is all lowercase so names are easy to match.

Try it: in header.inc, change [sitenamevar] to [sitnamevar]. Demo #3 ↗

4Naming a variable after a WebDNA tag

A variable can take over a real tag. After [text]date=hello[/text], every [date] on that page prints hello instead of today’s date. A formatted tag breaks too: the footer’s [date format=%Y] prints helloformat=%Y]. This is why the class convention ends every variable name in var: a name like datevar can never match a WebDNA tag (tested: [datevar] and [date] both work side by side).

Try it: add [text]date=hello[/text] to the bottom of vars.inc and look at the footer. Demo #4 ↗

5Stray spaces and line breaks inside a value

Everything between = and [/text] is the value, including a space or an Enter. A space at the end of pathvar is copied into cssvar, incvar, and imgvar too, so every include turns into Error: template '/citi/coding/2027/1/jdm/mysite/ includes/header.inc' not found and the page loses its styling. The space before includes in the error message is the clue.

Try it: add one space before [/text] on the pathvar line. Read the error, then remove the space. Demo #5 ↗

6Variables last for one page only

Variables are set fresh each time a page is built. A value set on the homepage does not exist on the About page. That is why vars.inc is included at the top of every page: a page that skips it gets Error: template '[incvar]header.inc' not found for every include. Demo #6 ↗

7A path variable built before pathvar

Inside vars.inc, order matters too. If the cssvar line sits above the pathvar line, cssvar is built while pathvar does not exist yet, so it stores the plain text [pathvar]css/. The stylesheet link becomes href="[pathvar]css/style.css" and the page loses all its styling, while images and links still work.

Try it: move the cssvar line above the pathvar line in vars.inc, then open View Source and find the stylesheet link. Demo #8 ↗

Teacher Watch List

MySite integration
  • Convert one page first. Homepage plus all three includes working with variables before touching the other pages.
  • Find every leftover path. Students miss one or two hard-coded /citi/coding/... paths, usually images in the bodycopy. In Sublime, Find (Cmd/Ctrl+F) for /citi/ in each file; the only match left should be the vars.inc include line.
  • Page with no styling? Check the stylesheet link in View Source. [pathvar]css/ there means cssvar is above pathvar in vars.inc (Tricky Part 7). A short path like css/style.css means a leftover from before includes (Break It Demo #7).
  • Plain text in brackets on the live page means the variable is used before it is set, misspelled, or has a space around the =. Check in that order.
  • Blank lines at the top of View Source come from the lines in vars.inc. They are harmless; browsers ignore whitespace before <!DOCTYPE html>.
  • View Source shows values, never variables. Same server-side rule as [date] from the last lesson.
  • Apostrophes and quotation marks in a site name are fine in text and in the <title>. A name with " inside an attribute like alt="[sitenamevar] logo" will cut the attribute short; suggest avoiding double quotes in the site name.

Lesson Flow

~55 minutes
TimePhaseWhat happens
5 min Warm-Up / Hook “Your site just moved to a new folder. How many places would you have to fix?” Students count every appearance of their full site path across their includes and pages (walkthrough, Part A). Typical answer: 15 to 30.
10 min Direct Instruction Set vs. use. Algebra connection (“let x = 5”). Live demo: build vars.inc on a page, starting with pathvar and then cssvar built from it; include it first, swap the CSS link to [cssvar]style.css, reload. Nothing looks different, and that is the point. Show the titlevar pattern and the browser tab changing per page.
25 min Guided Practice: Walkthrough Students follow the walkthrough steps: create vars.inc, add it to the homepage, convert the three includes, convert the homepage, test, then convert the remaining pages and add a titlevar to each. Final check: Find /citi/ in every file.
10 min Break It Pairs run Tricky Parts 1 through 4 on their own sites: predict, test, record, undo. Project the matching Break It demos to confirm results. Debrief the date takeover as a class; it surprises everyone.
5 min Rebrand & Exit Ticket Students change sitenamevar in vars.inc only and confirm the new name on every page and in every browser tab. Exit ticket on the walkthrough.

Assessment

Formative: Live MySite check: vars.inc exists and is the first line of every page; the only hard-coded full path left is the vars.inc include line; every link, image, CSS, and include path uses pathvar, imgvar, cssvar, or incvar; the site name and author come from variables; every page has its own browser-tab title; no bracketed variable names appear on any page. Walkthrough Break It entries reviewed for reasoning.

Exit ticket (completion-graded): “Why must the vars.inc include line use the full path instead of [incvar]? Name one other change that now takes one edit.”

Extension: Give every page a fallback title so a forgotten titlevar never shows brackets. Put this in header.inc just above <!DOCTYPE html>: [showif [titlevar]=[raw][titlevar][/raw]][text]titlevar=Home[/text][/showif]. It checks whether [titlevar] is still plain text (never set) and, if so, sets it to Home. (Preview of [showif].)