CiTi · Computer Coding · Year One · Unit 3

Text Variables: One Settings File for MySite

Student Walkthrough

The Big Idea

A variable is a name that holds a value. You set it once. Then you can use it anywhere, as many times as you want. Change the value in that one spot, and every place that uses it changes too.

1. Set it

Use a [text] tag: the name, an equals sign, then the value. This prints nothing on the page.

[text]sitenamevar=Jordan's Lego Site[/text]
2. Use it

Put the name in square brackets. The server swaps it for the value.

<h1>[sitenamevar]</h1>

You will keep all your settings in one new file, includes/vars.inc. Every page reads that file first.

Class rule: every variable name is lowercase and ends in var, like pathvar and sitenamevar. That way you can always tell your variables apart from WebDNA’s own tags.

Part A: Count It

Right now your full site path (/citi/coding/2027/1/YOURINTS/mysite/) is typed all over your site. Open each file and count how many times it appears. In Sublime, Cmd+F (Mac) or Ctrl+F (Windows) and search for /citi/.

header.inc
nav.inc
footer.inc
All my pages
Total
If your site moved to a new folder, what would you have to do?

Part B: My Settings

Fill these in first. They become the values in your vars.inc.

pathvar: my full site path (starts and ends with /). This is the only path you type.
sitenamevar: my website’s name
author: my first and last name
You do not type your CSS, includes, or images paths. cssvar, incvar, and imgvar are built from pathvar for you (Step 2).
Avoid double quotation marks (") in your site name. Apostrophes are fine.

Part C: Walkthrough

Do the steps in order. Save in Sublime after each one, then check your live page. Check the box when a step works.

  1. Make the settings file. In CyberDuck, open your mysite/includes folder. Make a New File named vars.inc. Right-click it and choose Edit with Sublime Text.

  2. Type your settings. Use your own values from Part B. One variable per line. No spaces around the =.

    [!] 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]

    Lines starting with [!] are WebDNA comments. The server skips them, so they are a safe place for notes.

    Look at the cssvar line: its value uses [pathvar]. The server fills in your path, so cssvar becomes your path plus css/. Only the pathvar line is different for each student. Copy the three lines under it exactly.

  3. Load the settings on your homepage. Open mysite/index.html. Add these two lines at the very top, above your header include. The first line is the only place that still uses your full path.

    [include file=/citi/coding/2027/1/YOURINTS/mysite/includes/vars.inc] [text]titlevar=Home[/text]
  4. Switch the homepage include lines to use [incvar]. It already ends with includes/, so just add the file name. Save and check your live page. It should look exactly the same as before.

    [include file=[incvar]header.inc] [include file=[incvar]nav.inc] ...your bodycopy... [include file=[incvar]footer.inc]
  5. Update header.inc. Use [cssvar] in the CSS link and [imgvar] for the logo image. Use [titlevar] and [sitenamevar] in the title, and [sitenamevar] in your <h1>.

    <title>[titlevar] | [sitenamevar]</title> <link rel="stylesheet" href="[cssvar]style.css"> ... <img src="[imgvar]logo.jpg" alt="[sitenamevar] logo"> <h1>[sitenamevar]</h1>

    Check: your browser tab should now say Home | your site name.

  6. Update nav.inc. Every link starts with [pathvar]. Notice there is no / after it: every path variable already ends with one.

    <a href="[pathvar]">Home</a> <a href="[pathvar]about/">About</a> <a href="[pathvar]author/">Author</a> <a href="[pathvar]photos/">Photos</a>
  7. Update footer.inc. Use [authorvar] and [sitenamevar] in place of typed names.

    <p>&copy; [date format=%Y] [authorvar] &middot; [sitenamevar]</p>
  8. Do your other pages (About, Author, Photos). Each page gets the same top lines, but its own titlevar. Change the include lines to [incvar], and change any images in the bodycopy to [imgvar] plus the file name.

    [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]
  9. Hunt for leftovers. Search every file for /citi/. On each page, the only match should be the vars.inc line. In the three include files, there should be none. Then open every page on your live site and click every nav link.

Part D: Break It On Purpose

One change at a time. Predict first, test on your live page, then undo it before the next one.

1. On your About page, move the titlevar line below the header include

I predict
What happened
Why

2. In vars.inc, put a space before the = on the sitenamevar line

I predict
What happened
Why

3. In header.inc, misspell [sitenamevar] as [sitnamevar]

I predict
What happened
Why

4. Add [text]date=hello[/text] to the bottom of vars.inc, then look at your footer

I predict
What happened
Why

5. In vars.inc, move the cssvar line above the pathvar line

I predict
What happened
Why

Variable Rules to Remember

Part E: Rebrand Test

Change sitenamevar in vars.inc to something new. Check every page and every browser tab. Then change it back (or keep it).

Files I would have edited before vars.inc
Files I actually edited

Success Criteria Check-In

Check each one when you feel confident you can do it.

Exit Ticket

Why must the vars.inc include line use the full path instead of [incvar]? Name one change to my site that now takes just one edit

My Notes

Use this space for anything: questions, reminders, code you want to keep.