Class Three: Difference between revisions

From TalossaWiki
Jump to navigation Jump to search
Line 265: Line 265:


==Assignment==
==Assignment==
Wow, what a complicated class this time around!  Now let's see you use it all.  Don't be afraid to ask for help, or re-read the lesson.
#Create a third and final article on any topic here on the wiki.  On this article, use ''either'' a table or a new template that you have created.  Your template must have at least one variable - it can be either named or unnamed.  Remember to categorize your article and any templates you make, and remember not to make an orphan or a dead-end!


[[Category:Instruction]]
[[Category:Instruction]]

Revision as of 01:23, 9 July 2012

In this, the last class, we will learn how to create tables, as well as how to use some templates. Both of these things are very versatile, but can get very complicated. Even though you won't be a master of the subject when we finish, you should know enough to use basic tables and templates - and perhaps you'll be interested enough to keep learning on your own!

Tables

You're probably familiar with tables - a way of showing data arranged into columns and rows. They can be a useful way of working through options, and can even be helpful in making decisions. Here is a table, for example, about when it is a good idea to order a pizza:

Are you already eating a pizza? Then you should...
No Order a pizza, immediately.
Yes Order a second pizza.

On the wiki, tables are used for a lot of things. They can get really complicated, so we'll just learn how to make one simple kind of table for now.

All tables begin with a {| and end with a |}. If you forget either of those sets of symbols, then the table will not work correctly. It's also important to remember that the {| must be at the start of a new line. If you try to start a table in the middle of a line, then it doesn't work.

So the first thing we do is lay out our table start and table end:

{|

|}

Now we have to add some data. We'll start with the simplest possible table: one cell of information. To build a cell, you just start with a pipe symbol, and then put in whatever information you want. All cells must start with a pipe symbol.

{|
|Pizza
|}

Now, this is a boring table. It's so boring, you actually can't even tell it's a table. Here it is:

Pizza

We can make it a little better - make it actually look like a table - if we tell the table to look different. We can do that by instructing it to look like a "wikitable," which is a standard and very common style of table. To do that, you just add class="wikitable" right after the table start. It's a sort of code word: that one little command is actually just the trigger for a whole bunch of hidden instructions, cached away elsewhere on the wiki.

So our table now looks like this in code:

{| class="wikitable"
|Pizza
|}

And that gives us this:

Pizza

Still very boring, but a little more like a table. Let's add a title. We do that with a plus sign, right after the start of the table. It has to come after a pipe, at the start of a new line.

{| class="wikitable"
|+Delicious table
|Pizza
|}
Delicious table
Pizza

Bue in the mwith one cell and a title still doesn't give more information. Let's add another row of information. To do that, we tell the table we want a new row with a |-, then we add the new row (which, remember, has to start with a |.

{| class="wikitable"
|+Delicious table
|Pizza
|-
|Ice cream with chocolate sprinkles
|}
Delicious table
Pizza
Ice cream with chocolate sprinkles

Now notice that the table has automatically expanded! Not only does it have a new row, but the entire table is bigger, to accommodate the length of the new data! Amazing! Now it's really starting to look like a table.

Let's add an entire new category of information, though. We'll add another column to the table. We do that by just expanding horizontally: just append a double pipe, || to the rows you want to expand.

{| class="wikitable"
|+Delicious table
|Pizza || Cheese
|-
|Ice cream with chocolate sprinkles || Sugar
|}
Delicious table
Pizza Cheese
Ice cream with chocolate sprinkles Sugar

Okay! Now this looks seriously like a table, don't you agree? Bue we want to label this information... what does "cheese" have to do with "pizza," for example? To add a label, we use an exclamation point near the start of the table. Each exclamation point will be the label for a column. So if you have two columns and you want to label both, you need two exclamation points. Also, we need a "new row" symbol after them, so the wiki understands exactly what we want.

I have two columns, but I only want to label the second. So I put two exclamation points at the start of two new lines at the top of the table, and put my desired label in the second one.

{| class="wikitable"
|+Delicious table
!
!Why is it delicious?
|-
|Pizza || Cheese
|-
|Ice cream with chocolate sprinkles || Sugar
|}
Delicious table
Why is it delicious?
Pizza Cheese
Ice cream with chocolate sprinkles Sugar

And there you have it! You can do all sorts of things from this basic table! I'll give some examples, now.

Examples

Add a new row

{| class="wikitable"
|+Delicious table
!
!Why is it delicious?
|-
|Pizza || Cheese
|-
|Ice cream with chocolate sprinkles || Sugar
|-
|Pie || Fat
|}
Delicious table
Why is it delicious?
Pizza Cheese
Ice cream with chocolate sprinkles Sugar
Pie Fat

Add a new column

{| class="wikitable"
|+Delicious table
!
!Why is it delicious?
!Bad for you?
|-
|Pizza || Cheese ||
|-
|Ice cream with chocolate sprinkles || Sugar ||
|}
Delicious table
Why is it delicious? Bad for you?
Pizza Cheese Shut up
Ice cream with chocolate sprinkles Sugar Go away I'm eating

Add images

{| class="wikitable"
|+Delicious table
!
!Why is it delicious?
|-
|Pizza || Cheese
|-
|Ice cream with chocolate sprinkles || Sugar
|-
|Dog || [[Image:Dog.jpg|100px]]
|}
Delicious table
Why is it delicious?
Pizza Cheese
Ice cream with chocolate sprinkles Sugar
Dog Dog.jpg

Others

Tables can accept all sorts of parameters. The whole table can get an argument, like class="wikitable", or you can give a row an argument if you put the parameter after |-, or an individual cell can get a parameter if you preface it with the parameter and a pipe. Here are some other parameters, and an example of them in action:

{| style="background-color:lightblue" align="center" border="1"
|+'''Delicious table'''
!
!Why is it delicious?
|- align="right"
|height="100px"|Pizza ||Cheese
|-
|style="background-color:pink"|Ice cream with chocolate sprinkles ||style="color: red"| Sugar
|}
Delicious table
Why is it delicious?
Pizza Cheese
Ice cream with chocolate sprinkles Sugar

There's a lot more to discover, if you're still curious!

Templates

On a wiki like TalossaWiki, you can design and use special pages that trigger when you activate the code word. You just write up on a separate page the text, image, or table that you want to appear, and then every time you use the code word, the wiki supplies what you wrote before. These special sorts of pages are template pages, and they're activated with two pairs of curly brackets: {{ }}. This might sound complicated, but actually it's really simple.

Let's say that I get tired of typing out a long bit of text, like, "Hello and welcome to the class! We will learn a lot, and I'm glad to have you!" You type it to ten students, twenty students... you'll get sick of it! So it's better to arrange for the wiki to do that typing for you.

We'll call this template "Example," because - well, it's an example! And to make it, we just go to Template:Example. If you go there now, you see that the only contents are that sentence I just wrote, in bold. That looks a little weird, but don't worry, very few people are going to be looking at that page. The real magic happens when we call that template from a page. I'll do it here, now, with {{Example}}:

Hello and welcome to the class! We will learn a lot, and I'm glad to have you!

Just like magic! Now the amount I have to type to greet a student is only twelve characters, instead of sixty-odd!

Note: It doesn't matter if you capitalize the first letter, but the rest of a template's name 'is case-sensitive.

All templates operate on this same basic principle: the wiki replaces the template code with whatever is on the template page.

Sometimes this can insert very complicated things onto multiple pages. This makes it easy to make changes on all those pages. For example, Template:Cabinet is on all pages for offices of the Cabinet. To put it on a page, you just have to type {{cabinet}}. The result is a fancy nav-bar.



And if someone wants to make changes to that bar, they only have to change the Template page, rather than changing every single cabinet page. It's much more convenient.

Variables

Most templates are far more complicated than Template:Example, of course. In fact, most templates operate based on "variables." When you type the code word, you can also add a bit of extra information that gets processed by the template.

Template:Hatnote is a template that accepts a variable, for example. If you type {{Hatnote|This is a message.}}, then everything after the pipe is accepted as input to the first variable. So the page will show the viewer this:

This is a message.

Look back on Template:Hatnote. Click "Edit" so you can see the code - although don't make any changes!

You'll notice that {{{1}}} there - that is the variable. Because it's an unnamed variable, the wiki just automatically assumes it's {{{1}}} - that's the default name for a variable. It makes it easy to write the template, because you can just put {{hatnote|anything at all}}. Fast and simple.

Note: Templates also get categorized.

Other templates are more complicated. For example, look at Template:Org. This template accepts two unnamed variables, {{{1}}} and {{{2}}}. So to call this template, you might write {{org|8|1}}. The template plugs in your two bits of input into its formula, replacing {{{1}}} and {{{2}}}with 8 and 1. Looking at the template page, we can see the result is that the template will replace {{org|8|1}} with [[Organic Law (text)#8.1|Org.8.1]]. And from our last two lessons, you might recognize that this is an internal link to a section of a page. It would display like this: Org.8.1

Named variables

Lots of templates don't have the unnamed variables ({{{1}}}, {{{2}}}, {{{3}}}, etc.) Instead, they have specific named variables.

Let's look at an example you'll see a lot around the wiki: Template:Office.

You can see that there are a bunch of different variables. All of them have names. So if you click "Edit" and look at the code, you won't see {{{1}}} and {{{2}}}, but rather {{{name}}} and {{{logo}}}. When you're putting the template onto a page, it will only understand what you want if you call these variables by their proper names. You can't say {{Office|Ben|logo.gif}}, because the variables need a name! It would have to be {{Office|name=Ben|logo=logo.gif}}.

Take a look at the Seneschal page. Click "Edit" to see the source code. You'll see that Template:Office is being used. If you still need help, look back at Template:Office and notice that there are sample instructions on how to use it - you just have to fill in the variables (or just delete the ones that don't apply). So easy!

Assignment

Wow, what a complicated class this time around! Now let's see you use it all. Don't be afraid to ask for help, or re-read the lesson.

  1. Create a third and final article on any topic here on the wiki. On this article, use either a table or a new template that you have created. Your template must have at least one variable - it can be either named or unnamed. Remember to categorize your article and any templates you make, and remember not to make an orphan or a dead-end!