Community Central
Community Central
Avin ~ παρυηzεΙ ~ Slay
Avin-blog-photo My Blogs:
CSS Guides
Other Users Helpful Blogs
Jr Mime's Blogs:

Rofl's Blogs On Infoboxes:

Fubuki's Blogs

So some of you may have seen the {{#if: blah coding in here }} or {{#switch: blah coding in here }} . 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!

{{#if: {{{seasons|}}}|
{{!}} style="width:50%; padding-left:15px; border-radius:5px; background-color:#3366CC; color:#f2f2f2; font-size:100%;" {{!}} '''Seasons:'''
{{!}} {{#switch: {{{seasons}}}
|season1 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]
|season1-2 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]<br>[[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]
|season2 = [[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]
|season2-3 = [[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]<br>[[Season 3]] [[:Category:Season 3 Characters|Characters]] [[Category:Season 3 Characters|Characters]]
|season1-2-3 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]<br>[[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]<br>[[Season 3]] [[:Category:Season 3 Characters|Characters]] [[Category:Season 3 Characters|Characters]]
|#default = {{{season|}}} }} |}}

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 |seasons= my season is on fire! 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 |seasons= 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 |seasons=my season is on fire! 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!

{{Psychics at work <this is my template's name>

|Name= Shawn Spencer <his name of course>

|seasons= My season is on fire! <because I put this in, "My season is on fire!" will show up when I hit publish.> }}

{{Psychics at work <this is my template's name>

|Name= Shawn Spencer <his name of course>

<now seasons won't show up, because I didn't put it in the template.> }}

The Styling[]

{{!}} style="width:50%; padding-left:15px; border-radius:5px; background-color:#3366CC; color:#f2f2f2; font-size:100%;" {{!}} '''Seasons:''' This gives us the following row, I've also added a border and width to the infobox, so that it looks shapely:

Seasons:

Now if we add {{!}} {{{seasons}}} to our row style, we get the field.

Seasons: {{{seasons}}}


{|style="border:2px solid #3366CC; width:300px; border-radius:7px;" <this is my added border and width>
{{!}} style="width:50%; padding-left:15px; border-radius:5px; background-color:#3366CC; color:#f2f2f2; font-size:100%;" {{!}} '''Seasons:''' <this is the name of the row with its styling.>
{{!}} {{{seasons}}} <this is the field that we type stuff into>
|}

Now if we had put {{{seasons|}}}, It would have looked like this:

Seasons:

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]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]
|season1-2 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]<br>[[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]
|season2 = [[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]
|season2-3 = [[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]<br>[[Season 3]] [[:Category:Season 3 Characters|Characters]] [[Category:Season 3 Characters|Characters]]
|season1-2-3 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]<br>[[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]<br>[[Season 3]] [[:Category:Season 3 Characters|Characters]] [[Category:Season 3 Characters|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 |seasons=fire 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:
|season1 = it's better on dvd...,
|season1-2 = oh season one and two, shazzam!,
|season2 = haha season two was great!,
|season2-3= twas a sad ending,
|season1-2-3= We're going to be here for a while

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!

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

UPDATE[]

Okay, Rofl asked an awesome question! "Does #switch: need #if:?" The answer is..... *Drumroll* #switch does not need #if to work!

In this blog, the way the main coding is set up is so that if you don't put anything for {{{seasons}}} it doesn't even bring up the row! Here's what the code would look like without the #if:

{{!}} style="width:50%; padding-left:15px; border-radius:5px; background-color:#3366CC; color:#f2f2f2; font-size:100%;" {{!}} '''Seasons:'''
{{!}} {{#switch: {{{seasons}}}
|season1 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]
|season1-2 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]<br>[[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]
|season2 = [[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]
|season2-3 = [[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]<br>[[Season 3]] [[:Category:Season 3 Characters|Characters]] [[Category:Season 3 Characters|Characters]]
|season1-2-3 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]<br>[[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]<br>[[Season 3]] [[:Category:Season 3 Characters|Characters]] [[Category:Season 3 Characters|Characters]]
|#default = {{{season|}}} }}

Now with this coding, the seasons row will show up no matter what. However, the snippet right here: |#default = {{{season|}}} }} makes it so that {{{seasons}}} doesn't show up when we click publish on the template...

Seasons:

If we remove that little | then the {{{seasons}}} will show up.

Seasons: {{{season}}}
{|style="border:2px solid #3366CC; width:300px; border-radius:7px;"
{{!}} style="width:50%; padding-left:15px; border-radius:5px; background-color:#3366CC; color:#f2f2f2; font-size:100%;" {{!}} '''Seasons:'''
{{!}} {{#switch: {{{seasons}}}
|season1 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]
|season1-2 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]<br>[[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]
|season2 = [[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]
|season2-3 = [[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]<br>[[Season 3]] [[:Category:Season 3 Characters|Characters]] [[Category:Season 3 Characters|Characters]]
|season1-2-3 = [[Season 1]] [[:Category:Season 1 Characters|Characters]] [[Category:Season 1 Characters|Characters]]<br>[[Season 2]] [[:Category:Season 2 Characters|Characters]] [[Category:Season 2 Characters|Characters]]<br>[[Season 3]] [[:Category:Season 3 Characters|Characters]] [[Category:Season 3 Characters|Characters]]
|#default = {{{season}}} }}
|}

––Slayingthehalcyon  (talk)