MyNameIsJason

Joined 27 September 2008
No edit summary
Line 42: Line 42:
==#if template==
==#if template==
<pre>{{#if:{{{release d|}}}|on|in|}}</pre>
<pre>{{#if:{{{release d|}}}|on|in|}}</pre>
This fills in the first sentence of the lede of an article with one of two options: the word "on," (i.e. "on March 12") or the word "in" (i.e. "in 2023"), depending on whether or not the user inputs a release date (i.e. "March 12") into the infobox. If they only put 2023 as a year and leave the release date blank, the template will "by default" make the lead "in {{{year}}}".<br><br><br>
I used this example in the [[Template:Album page machine|album page machine template]]. It fills in the first sentence of the lede of an album page with one of two options: the word "on," (i.e. "on March 12") or the word "in" (i.e. "in 2023"), depending on whether or not the user inputs a release date (i.e. "March 12") into the infobox. If they only put 2023 as a year and leave the release date blank, the template will "by default" make the lead "in {{{year}}}".<br><br><br>
<big>but you don't have to remember that to understand this</big><br><br><br>
<big>but you don't have to remember that to understand this</big><br><br><br>
Just think this:
Just think this:
<pre>{{#if:{{{template parameter|}}}|yes|no|}}</pre>
<pre>{{#if:{{{template parameter|}}}|yes|no|}}</pre>
I should '''replace the "yes" slot with whatever I want to appear if the template parameter is filled in by the user'''. In this case it actually doesn't matter what they input - they can keysmash as long as it doesn't trip up the syntax. The #if template changes the behavior of a template to not merely call and replace information - in a way it is an simpler task for the wiki to process: "is the parameter empty or not?" If it is, the template will [[Wiki:Help:Transclude]] whatever you have in the "yes" slot to the page.
I should '''replace the "yes" slot with whatever I want to appear if the template parameter is filled in by the user'''. In this case it actually doesn't matter what they input - they can keysmash as long as it doesn't trip up the syntax. The #if template changes the behavior of a template to not merely call and replace information - in a way it is an simpler task for the wiki to process: "is the parameter empty or not?" If it isn't empty, the template will [[Wiki:Help:Transclude]] whatever you have in the "yes" slot to the page.
<pre>{{#if:{{{template parameter|}}}|yes|no|}}</pre>
<pre>{{#if:{{{template parameter|}}}|yes|no|}}</pre>
I should '''replace the "no" slot with whatever I want to appear "by default."''' In the case that the editor doesn't fill this parameter in, or doesn't even list the parameter at all, the template will display whatever you type in the "no" slot. If you're reading this, go back to the release date example above and read it again - I think it will make more sense.
I should '''replace the "no" slot with whatever I want to appear "by default."''' In the case that the editor doesn't fill this parameter in, or doesn't even list the parameter at all, the template will display whatever you type in the "no" slot. If you're reading this, go back to the release date example above and read it again - I think it will make more sense.