Jump to content

User:Sushant savla/sandbox/template tutorials

From Wikipedia, the free encyclopedia

Phase I discussion

[edit]

So, what are templates? Templates are pages that are embedded (transcluded) into other pages to allow for the repetition of information.

There are two ways to use a template, one direct use, and another substitute. For now, we'll start with simple direct use. To use any template you surround it with two curly brackets {{ and }}. For example you type {{Like}} and you get the result 👍 Like. The table below shows some codes and the results.

Code Result
{{+1}} +1
{{Talk header}}
{{Welcome-short}} ==Welcome!==

Hi, Sushant savla/sandbox. Welcome to Wikipedia! Thank you for your contributions. I hope you like the place and decide to stay. Our intro page contains a lot of helpful material for new users—please check it out! If you need help, visit Wikipedia:Questions or ask a question on your talk page.

Now you can paste the same template with 2 curly brackets in hundreds of pages. So there is one main page/source page, i.e. the template page, and that is being used on many pages. Do you get this? Now, suppose one template is used on hundreds of pages, everytime it is calling the source code from the template. Or in other words no matter whatever the page is, the code {{Welcome-short}} is showing the code of the template. Also if the template changes, all pages will see the change.

So, there is another way of using the template. Sometimes we can substitute a template also (sometimes it is needed as well by the template). Substituting is putting the source directly. Here when you substitute you paste the source of the template on a page. Substitution is done with subst: before the template name like {{subst:Welcome}}. When you paste {{Welcome}} you use the template, the source is at Template:Welcome. But, when you use {{subst:Welcome}} then you paste the source of a template on a page.

Tasks
Finish these 2 tasks please

  • Read the lead section of Help:Substitution, also read the lead section only of Wikipedia:Substitution (you don't need read the entire page right now)
  • Go to your sandbox and try a) put this code {{Welcome}}, b) save the page, c) open the page and see the code, now without removing the last line, below that put {{subst:Welcome}}, save the page, d) open the page once again, and examine the result/code. Do you see difference between the two results? Respond below once you are done.

--Titodutta (talk) 14:44, 27 April 2020 (UTC)

@Titodutta:, Apologies for the delayed response, was busy in Indic Proofreadthon Reviewing and other professional errands. I have completed the Reading and Task, Under stood the basic idea of Template and Substitution. Task is practiced here User:Sushant savla/sandbox/Template Assignment. Thank you. --Sushant savla (talk) 11:22, 15 May 2020 (UTC)
  • It looks good to me. Let's move ahead. When you place/use a template you use 2 curly brackets {{ and }} such as {{Notice}} Now, let's learn something which uses three curly brackets. It is {{{ When you need to use a variable in a template, you use three curly brackets. Note, it is not 2, but 3 brackets. Let me give an example. In an a matchbox there might N number of match sticks. N might be any number between 0 and 50 (generally a matchbox contains upto 50 sticks). Suppose we have many matchboxes, we will use the N as a variable where value will change between 0 and 50. So let's write it in this way:
This matchbox has N sticks (N is a variable)
(Let's surround it with three {{{ so on-Wiki, it is understood as a variable) This matchbox has {{{N}} sticks
Do you understand this? This one sentence is a basic one line template. We put this sentence in different pages, and the value of N changes everywhere. Let's take another example, This editor has X edits. Here X is a variable. When you change the username or put this sentence "This editor has {{{X}}} edits, the value of X changes everywhere.
Variables are case-sensitive, and x and X are two different variables.
Tasks: Please go to these templates Template:Red and Template:Birth date, go to edit mode and try to find out the variables used there. Once you do this, we'll move ahead and create a simple template on sandbox. --Titodutta (talk) 00:03, 16 May 2020 (UTC)
@Titodutta:, I have Understood the idea of Variables. Task is practiced here User:Sushant savla/sandbox/Template Assignment#Assignment 2. Thank you. --Sushant savla (talk) 05:24, 16 May 2020 (UTC)

Please ask questions on this page, not on the other page. Yes, df is a variable as well. df means date first. You know a date can be written in multiple ways, the most 2 commons ways are DMY and MDY. Mahatma Gandhi was born on {{Birth date|1869|10|02}} produces (1869-10-02)October 2, 1869, now British English and Indian English uses DMY, so we specifically instruct to use "df" (date first) and {{Birth date|1869|10|02|df=y}} produces (1869-10-02)2 October 1869

Let's move on. We need 3 sandboxes. We may use User:Sushant savla/sandbox/1, User:Sushant savla/sandbox/2 and User:Sushant savla/sandbox/3. We'll need these 3 pages again and again now, so it is good to give simple names, and use consistently. The idea is the first of these 3 page will be treated as a template, and the second and third page will be used to test and apply the template. In this example consider /1 as template, and /2, /3 are pages where we are trying/using /1 (which is a template)

Now let's go to User:Sushant savla/sandbox/1 and put this sentence (without quotes) "The capital of the Indian state {{{A}}} is {{{B}}}" This becomes a simple one line template.

Now, let's go to User:Sushant savla/sandbox/2 , and put the code (do not copy <nowiki>) {{User:Sushant savla/sandbox/1|A=Karnataka|B=Bangalore}} In the template page 1 we used only variables A, and B. In page 2 we called the template 1, and put value for A and B. If you do it correctly you should get thi sentence "The capital of the Indian state Karnataka is Bangalore " as result once you save.

Task: Now go to User:Sushant savla/sandbox/3, use User:Sushant savla/sandbox/1 as template and other than Karnataka, try at least 3–4 other states. You need to use the same code of page 2 multiple times back to back and keep on defining the value. So on page 3, I want this result"

The capital of the Indian state Gujarat is Ahmedabad. The capital of the Indian state West Bengal is Kolkata. The capital of the Indian state Telanagana is Hyderabad

Theoritically we could use it on other pages, but we have used 3 sandbox for task already, won't take any other space. --Titodutta (talk) 06:13, 16 May 2020 (UTC)

@Titodutta:,Understood the concept of creating the page to be used as template and calling template in other pages. Created three pages as per task and completed the task.--Sushant savla (talk) 07:09, 16 May 2020 (UTC)
Task: Now go to /1 sub page and replace everything with (do not copy nowiki) <div style="border:1px solid red; text-align:center;">{{{A}}} is an Indian-language book, written by {{{B}}}. The book was first published in the year {{{C}}}</div> Here we are doing threee things: we are using three variables A, B, C, and the in the entire code, we are adding some design (in case we need to talk about design or CSS, HTML, we'll do it separately). Now go to /2 and /3 sandbox and fill the variable values from /1. We need complete sentences about 3–4 any book in the result page. --Titodutta (talk) 07:34, 16 May 2020 (UTC)
@Titodutta:,Created another template with three variables. Created result pages in User:Sushant savla/sandbox/2 & [User:Sushant savla/sandbox/3]]. Thank you. --Sushant savla (talk) 08:12, 16 May 2020 (UTC)

Random break 1

[edit]

A few things note:

  • Note1: A vairable is case sensitive and actually pretty sensitive. If in a templaten 4 variables are A, b. C, d. you have to call exactly 4 variables A, b (not B), C, d (not d). A pretty common variable is 1. In a lot of templates 1 is a common vairable, eg. Just under the random break section above I have used (without nowiki) {{Hatnote|1=This break is created to as this section became too long, making section-editing difficult}} Here Hatnote is the template, 1 is the value. For your template value was Karnataka or Bangalore, for this value is longer, of course the value may be longer, the idea is the same.
  • Note2: Not only the value, a variable may be of any length. We have named so far A, B, C. It can be anything such as {{{name}}}, {{{surname}}}, {{{family_name}}}, {{{image}}} etc. A machine does not need a meaningful variable name, human might need. That is why sometimes variables are created in such a way {{{birth name}}}, {{{birth year}}}. For a machine if you call the "birth year" anything else such as {{{dE@th year}}} it does not matter, however for make it easier to use for human, we try variables following the way human thinks. You might ask now can we have a variable in Indian language such as {{{જન્મ તારીખ}}}, the answer is of course, you can. But let's not do this, right at this moment. First we need to know labels. And also the risk (this is more of administrative and maintenance part, will come later, putting it in a new section "Parked topics")
  • Special New! Note3 Label and data: Now in this ssntence/variable "{{{A}}} is an Indian-language book, written by {{{B}}}. The book was first published in the year {{{C}}}" {{{A}}}, {{{B}}}, and {{{C}}} are called data. This "data" keeps on changing. Now, we might name/call these variables A, B, C. (or anything) Now these A, B, C are labels (without curly brackets). So a data is the code (the variable), a label is its name. You will need label and data in infoboxes a lot. Let me explain this further.
{{{name}}} is a simple variable. You should understand this very easily.
When we put it in a setence it might be like "The name of the person is {{{name}}}"
Now imagine an infobox parameter, it might be like
|name = {{{name}}}
In the example above the variable is {{{name}}}, and I have named/labelled the variable "name". So "name" (without brackets, generally displays on the left side on an infobox parameter) is a label (We'll see a direct example, once we talk about default value also)
In the example above the | separates different variables, there might be many variables and arguments like {{{name}}}, {{{age}}}, {{{parents}}} and so on, we use a | to separate
Note4: So far we have seen a variable like {{{A}}}, or {{{name}}}, which can be defined while using (I mean you define the value while using). But if the value us not defined, it remains blank, right? If you do not define A, and B, it won't show Karankaka and Bangalore. But, what if, we want a default value? For that we write like this (without nowiki): {{{name|Default value}}}. Let's take another example: "A popular website is {{{site|Wikipedia}}}". Here if the vairable site is defined as any website, it'll show that name. If the variable is not defined the default value Wikipedia will be taken.
Practice: One thing you need to note here. One reason I am going step by step is every step not only brings something new but also uses almost all the steps earlier. The 4th post I wrote actually captures the learning of earlier discussion also. By any chance if you did not udnerstand a step, there is a possibility you can't build on it in the next steps. Now, Note3, and Note4 just above I am going to simply use both in a sample template.
I have added new code at User:Sushant savla/sandbox/1. Please go to edit mode and check the code and look and understand the variables. Find out the variables. Now, your result at /2, and /3 should be broken, as I have called new variables.
Task Go to /2 page, and use /1 with default value. The result should show Sachin and all the things which are default. Now, go to /3 and use /1 template, but the result should be of someone of a poet, or author.
I'll stop here now, although I was thinking to go one more step. There are already too many topics in this part. If we should slow down, please let me know. Else, after this we'll have similar examples and tests, but things will be more stylish/complicated (however easy to udnerstand as we are going step by step). The idea is after some practice with these templates on /1, /2, /3, we'll go to actual mainspace templates, and create/improve a few templates. --Titodutta (talk) 00:22, 17 May 2020 (UTC)
@Titodutta: The discussion above has been very easy to understand, much easier because it is proceeding step by step and i get time to re-read it and understand it, which is generally not possible in classroom style trainings as time is limited.
I have understood the concept to Label & Data (variable), Variable being case sensitive, separating variables by pipe sign, assigning default value to a variable discussed above. I have following doubts:
(1)In the template /1 the image is defined in the 4th row, However it has automatically shifted to 2nd row, below the Caption. How?
(2)I could see one Label defined as "Above", Is it some sort of universally per-defined label?
(3)In /2, for practicing, I left data blank, In such situation there was no result, In case of blank data won't it take the default value?

--Sushant savla (talk) 05:07, 17 May 2020 (UTC)

Answers:
  1. 1) In /1 the image is in the 4th row. Yes, now note I have used something "template inside a template" I have used Template:Infobox first and created your template inside it. You can go to /1 (current version) and see it. Template:Infobox is the base template for all major infobox templates such as Infobox person, book. In infobox, a few parameters and their position are preset such as above, image etc. So, the image is coming at top. Now in your template, the way you'll define label1, label2, in the same order it'll come in the result, regardless of the order you define in the template. See to explain this, in /3 I have reordered the variables, but it is still taking the same order of /1.
  2. Yes, in addition to what I wrote in the last answer, above is generally at the top, below title. Read "above" section here. Gradually we'll see more similar things like subheader etc.
  3. Here on /2 the same variables "full_name=|name=|occupation=|image=" are called twice. See the current version of /2 first {{User:Sushant savla/sandbox/1|full_name=|name=|occupation=|image=}} the variables are called. And again {{User:Sushant savla/sandbox/1}} the variables are attempted to call once again. At /3 also variables are also called multiple times, however every variable value is different such as Premchand, Vivekananda (not Vivekanand ) etc. However at /2 a variable is called twice, and at both the time the value is blank. So it is ignoring it altogether. Tryit: Go to /2 and add some value to the second use, not the first one. Now it should ignore the first use altogether, where everything is blank.
Task: in case you understand the last use of a simple infobox with 3 or 4 variables, now let's make it a little smarter. Let's create an infobox in "COVID-19 in Indian district" infobox template. We don't have such a template (and most probably here on English Wikipedia we won't need as well). However no issue in learning how to create one. I'll do the initial help and add only the first 2–3 lines of it, then you have to take it ahead. Go to /1 put this code
{{Infobox
| above = [[COVID-19 in India|COVID-19]] in {{{above|''unknown district''}}}
}}
Now, your task is after |above, add at least 7–8 variables, first case, confirmed cases, lockdown_status, deaths, and whatever else you find interesting. At least 1 variable should capture "image" for this use variable {{{image}}} only, as it is defined in Template:Infobox. After /1 becomes pretty informative, go to /2 and /3 and define /1 variables for 2 different Indian districts. You don't need to rightly put all correct infomation related to a district COVID-19. I don't want exact COVID-19 data, or image. Any random value of confirmed, death would work. Does it make sense? --Titodutta (talk) 06:10, 17 May 2020 (UTC)
@Titodutta:I have created added few variables in the practice template. and Results are in /2. I have one doubt:
(1) In Infobox there will be some items which may not have corresponding Label. They will just be variables. e,g, Image description, which we put below the image, what should be the treatment to deal with them? --Sushant savla (talk) 05:47, 18 May 2020 (UTC)
  • Cool. Use {{{caption}}} variable for image caption. Now you understand label and data, data is a variable, and label is the name of the data/variable which appears on the left side on the infobox (or similar template). Task: now create another infobox like COVID-19 at /1. "My friends" and use variables such as first_met, gender, meeting_frequency, and so on. The variables will be with a bar, not {{{variable}}}, but use {{{variable|}}} Make sure you write about imaginary friends in the example usage, and no real details, specially email, phone number, address should be there. For image use any image from Commons. Now, the task has more to do. The labels will be in Gujarati (not the variables). There should be at least 1 header (see #Template:Infobox#Usage). Last time I gave you the first 2–3 lines of code. This time you have to start everything from scratch. This will help to practice a little more before we move on. Do this on /1 and /2 (not on /3, see task below for /3)
  • Question: When we started this discussion, one thing you asked "suppose we need to add a parameter in an infobox, what should we do?" A one-line answer could be "you need to change or add a new variable in the template". Now after this discussion on this page, do you understand "you need to change or add a new variable i the template"? Or suppose in infobox person we need to add a new parameter "Aadhar number", can you add this paramter? (don't do it though)
  • Task 2: Please also read mw:Help:Magic_words#Variables, you may test things at /3. Try different Magic words variables there. These are pretty easy to understand. However feel free to ask question --Titodutta (talk) 07:28, 18 May 2020 (UTC)
@Titodutta:Task 1- I have created the template "My friends" as directed. If i do not mention any value against the label, it will not be reflected in the infobox. --Sushant savla (talk) 15:58, 20 May 2020 (UTC)
@Titodutta:Task 2 - Read it, did not understand much. what i understood is to get some typical standard output we have pre-defined wrods which return dynamic / stats values. --Sushant savla (talk) 15:59, 20 May 2020 (UTC)

Parked topics

[edit]
  1. Should or should not we create variable in non-English language? (parked on 00:22, 17 May 2020 (UTC))