User blog:Ephemeral Hiraeth/The If and the Switch

So some of you may have seen the. Well, have no fear, because there is almost always a solution to the problem! This blog will hopefully have you coding with the #if and the #switch by the time you're done reading!

The Code
Here below, I have a selection of coding from a wiki for a TV show, the coding will be understandable to some users, which is a good thing! For those of you who have absolutely no clue what all this does, don't worry, I'm going to break it down bit by bit, and show you which piece I'm talking about as I break it down. c: Lets get started!

Breaking down the If
Okay so first of all we have the following code: {{#if: {{{seasons|}}}|

Now, to call up an #if, we have to use two "{" brackets, just like when we call up any other template. (Make sure you close it with two "}" brackets before you publish your work! Otherwise your coding won't work.) Now the {{{seasons|}}} is what the #if statement is looking for. The {{{seasons "|" }}} means that if you don't enter something into the seasons field, you don't see {{{seasons}}} in your published template.

Now, an #if statement looking for something? What, simple, all the #if is doing, is checking to see if we put  in our template! "Why would it do that?" you might ask. Well, this is so that we can hide certain information rows on a template! This is useful if you don't always want the row for a character's season listing to show up. This way, only the information that is entered, shows up on the template. This also means, that if a character doesn't have a large seasonal role in the TV show, you can leave leave  out of the template entirely!

To put this into better perspective, say I've made a page for Shawn Spencer, Psychic Detective. In his infobox, with our nifty coding, when I put in  it puts the text, "my season is on fire" in the template when we hit publish. Now if we had left it blank, the row with the information for seasons won't even show up when we hit publish!

The Styling
This gives us the following row, I've also added a border and width to the infobox, so that it looks shapely:

Now if we add  to our row style, we get the field.

Now if we had put, It would have looked like this:

Now Presenting Switches!
Now some of you may be like, "ZOMG! What do I do with all the stuff in the {{#switch: ????". Well, that's quite simple! In fact, it's awesome how simple and cool this nifty trick is. That being said, here's the code from our TV show template:

{{!}} {{#switch: {{{seasons}}}
 * season1 = Season 1 Characters
 * season1-2 = Season 1 Characters Season 2 Characters
 * season2 = Season 2 Characters
 * season2-3 = Season 2 Characters Season 3 Characters
 * season1-2-3 = Season 1 Characters Season 2 Characters  Season 3 Characters
 * default = {{{season|}}} }}

Okay so first what we want to do, is look at the  {{#switch: {{{seasons}}}  what this does, is it see if we put something like, "fire" into the template when we use it on a article page. If the template sees that we put  What it will do, is put "This season is on fire!" into the template when we hit publish. This saves a lot of typing, and can be a nifty trick for helping you categorize items, characters, episodes, and whatever else you can think of!

Here's how I have my TV show character template set up: after the {{#switch: {{{seasons}}} I have:

Each "part after the ='s sign" is what will be entered into the template if I put |seasons= season2 or |seasons= season1-2-3. This means that #switch is great for items that appear in different games in a series, or different characters that appear in different seasons, and so on and so forth! Now, you might say, "Slay you've left off that last little bit of the coding!" Well, that's great observation, because this part helps us out greatly!

Okay so, this part functions like a default, almost like a normal setting. tells the template what to make the seasons row be if we don't put anything into |seasons= via:. The best part about the default, is that the coding that we have has a  which means that the   won't show up if we don't enter any text.

––Slayingthehalcyon (talk)

{{User:Slayingthehalcyon/blogbottom
 * title= The If and the Switch
 * previous= Adding Emotes
 * next= ???}}