Difference between revisions of "Demo:IfStatement"
(11 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
This page tries to use a set of nested If Statement to demonstrate the logic of Template inclusion: | This page tries to use a set of nested If Statement to demonstrate the logic of Template inclusion: | ||
For example: If there is a book citation, it can be included using the <code>{{: | For example: If there is a book citation, it can be included using the <code>{{:PAGENAME}}</code> instruction. | ||
<nowiki>{{: | <nowiki>{{:Book/Working with MediaWiki}}</nowiki> | ||
{{: | {{:Book/Working with MediaWiki}} | ||
This entry has many attributes, some of the attributes may have empty(null) value. The goal is to demonstrate that we can use the <code>{{#If condition| YES | NO}}</code> structure to determine how to show certain content or not. | This entry has many attributes, some of the attributes may have empty(null) value. The goal is to demonstrate that we can use the <code>{{#If condition| YES | NO}}</code> structure to determine how to show certain content or not. | ||
For example: The data content in <code>{{: | For example: The data content in <code>{{:Book/Working with MediaWiki}}</code> can be seen here: | ||
<syntaxhighlight lang=MD> | <syntaxhighlight lang=MD> | ||
{{cite book | {{cite book | ||
Line 17: | Line 17: | ||
|edition=2nd | |edition=2nd | ||
|url=https://workingwithmediawiki.com | |url=https://workingwithmediawiki.com | ||
|location= | |location=[[Book/Working with MediaWiki|local page]] | ||
|publisher=WikiWorks Press | |publisher=WikiWorks Press | ||
|page= <!-- or pages= --> | |page= <!-- or pages= --> | ||
Line 45: | Line 45: | ||
<syntaxhighlight lang=MD> | <syntaxhighlight lang=MD> | ||
{{cite book | {{cite book | ||
|last= | |last=Koren | ||
|first=Yaron | |first=Yaron | ||
|author-link=Yaron Koren | |author-link=Yaron Koren | ||
Line 51: | Line 51: | ||
|edition=2nd | |edition=2nd | ||
|url=https://workingwithmediawiki.com | |url=https://workingwithmediawiki.com | ||
|location= | |location=[[Book/Working with MediaWiki|local page]] | ||
|publisher=WikiWorks Press | |publisher=WikiWorks Press | ||
|page= <!-- or pages= --> | |page= <!-- or pages= --> | ||
Line 61: | Line 61: | ||
{{cite book | {{cite book | ||
|last= | |last=Koren | ||
|first=Yaron | |first=Yaron | ||
|author-link=Yaron Koren | |author-link=Yaron Koren | ||
Line 67: | Line 67: | ||
|edition=2nd | |edition=2nd | ||
|url=https://workingwithmediawiki.com | |url=https://workingwithmediawiki.com | ||
|location= | |location=[[Book/Working with MediaWiki|local page]] | ||
|publisher=WikiWorks Press | |publisher=WikiWorks Press | ||
|page= <!-- or pages= --> | |page= <!-- or pages= --> | ||
Line 74: | Line 74: | ||
}} | }} | ||
==Using If | ==Using #If in Template== | ||
Let's look at the content of the Template:VerifiedAuthor: | Let's look at the content of the Template:VerifiedAuthor: | ||
<syntaxhighlight lang=MD> | <syntaxhighlight lang=MD> | ||
Line 82: | Line 82: | ||
The rendering result would show like this: | The rendering result would show like this: | ||
{{VerifiedAuthor|firstName= | {{VerifiedAuthor|firstName=|lastName=}} | ||
[[Category:If]] |
Latest revision as of 11:45, 30 November 2022
This page tries to use a set of nested If Statement to demonstrate the logic of Template inclusion:
For example: If there is a book citation, it can be included using the PAGENAME
instruction.
{{:Book/Working with MediaWiki}}
Koren, Yaron (2020). Working with MediaWiki (2nd ed.). local page: WikiWorks Press. ISBN 978-1540761149.
This entry has many attributes, some of the attributes may have empty(null) value. The goal is to demonstrate that we can use the {{#If condition| YES | NO}}
structure to determine how to show certain content or not.
For example: The data content in Koren, Yaron (2020). Working with MediaWiki (2nd ed.). local page: WikiWorks Press. ISBN 978-1540761149.
can be seen here:
{{cite book
|last=Koren
|first=Yaron
|author-link=Yaron Koren
|title=Working with MediaWiki
|edition=2nd
|url=https://workingwithmediawiki.com
|location=[[Book/Working with MediaWiki|local page]]
|publisher=WikiWorks Press
|page= <!-- or pages= -->
|isbn=978-1540761149
|date=2020
}}
Simple Case
Knowing that YES
can decide whether to show something or not, this feature can be applied in the following way.
{{#If: 1 |Something to show | Nothing to show|}}
The following is the actual result:
Something to show
{{#If: |Something to show | Nothing to show|}}
The following is the actual result:
Nothing to show
Template Coding
Knowing this feature, we can judge whether certain portion of a template would show or not.
For example, we can decide when a person doesn't have first and last name, the rendering result would raise some alarm:
{{cite book
|last=Koren
|first=Yaron
|author-link=Yaron Koren
|title=Working with MediaWiki
|edition=2nd
|url=https://workingwithmediawiki.com
|location=[[Book/Working with MediaWiki|local page]]
|publisher=WikiWorks Press
|page= <!-- or pages= -->
|isbn=978-1540761149
|date=2020
}}
Rendered result:
Koren, Yaron (2020). Working with MediaWiki (2nd ed.). local page: WikiWorks Press. ISBN 978-1540761149.
Using #If in Template
Let's look at the content of the Template:VerifiedAuthor:
=Welcome to Template:VerifiedAuthor=
This template will only show you the entry when both first and last name of an author is provided.
The rendering result would show like this:
This template will only show you the entry when both first and last name of an author is provided.