Help:Templates: Difference between revisions

From BoyWiki
 
(63 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Stub}}




A list of BoyWiki templates can be found on [[Portal:Template index]].


Templates are pages shown in [[Portal:Template index]]. This means any page whose name begins with "Template:", such as "[[Template:Documentation]]", can be used as a template. The content of a template can be added to a page by typing <nowiki>{{templatename}}</nowiki> while editing the page. When the page is later viewed, <nowiki>{{templatename}}</nowiki> is replaced by the content of the page "Template:templatename". If the page "Template:templatename" is later altered, all the pages with <nowiki>{{templatename}}</nowiki> in them will change automatically.
Any page whose name begins with "Template:", such as "[[Template:Documentation]]", can be used as a template. The content of a template can be added to a page by typing <nowiki>{{templatename}}</nowiki> while editing the page. When the page is later viewed, <nowiki>{{templatename}}</nowiki> is replaced by the content of the page "Template:templatename". If the page "Template:templatename" is later altered, all the pages with <nowiki>{{templatename}}</nowiki> in them will change automatically.


Amongst other things, templates are used to add recurring messages to pages in a consistent way, to add boilerplate such as template {{Tl|stub}} which indicates that the article is a fledgling.   
Amongst other things, templates are used to add recurring messages to pages in a consistent way, to add boilerplate such as template {{Tl|stub}} which indicates that the article is a fledgling.   
Line 14: Line 14:


==General==
==General==
Most templates are pages in [[Portal:Template index]]
Most templates are listed on [[Portal:Template index]]


Templates can contain any desired [[Help:Wikitext|Wikitext]], including calls to other templates. They have some limited programming capacities: customizable values (called [[#Parameters|parameters]]), calculation and branchings (using parser functions), and access to wiki-specific variables ([[Help:Magic words|magic words]]), such as dates, times, and page names. They may also contain tags which define which parts of the wikitext are to be included when the template is transcluded or substituted. This means that the appearance of the template page itself need not be the same as that of the transcluded content (for example, it can contain documentation, categories, etc. for the template).
Templates can contain any desired [[Help:Wikitext|Wikitext]], including calls to other templates. They have some limited programming capacities: customizable values (called [[#Parameters|parameters]]), calculation and branchings (using parser functions), and access to wiki-specific variables ([[Help:Magic words|magic words]]), such as dates, times, and page names. They may also contain tags which define which parts of the wikitext are to be included when the template is transcluded or substituted. This means that the appearance of the template page itself need not be the same as that of the transcluded content (for example, it can contain documentation, categories, etc. for the template).
Line 23: Line 23:


Also see: [[Help:Templates for beginners]]
Also see: [[Help:Templates for beginners]]
*'''''TEMPLATES are just blocks of saved text that have been given names'''''.  Some are ordinary text paragraphs and some contain wikitext to make headings, indents, tables, and the like.  In a simple case, by typing a template's name in the work, an entire block of text is added to the page with all of its formats and other parts, just as if it had been typed by the user.  This behavior can be repeated at any point that the user wants, and almost any work that is found on a wiki page could be placed within a template to do this.  The main effort as you might suppose, lies in its initial design.
*'''''NAMES of templates are assigned when they are first saved'''''. The '''name''' must be unique, and it is used when a template is ''called'' for use.  Sometimes other text is also used along with the name; it can include any '''options''' and '''parameters'''.     
*'''''OPTIONS allow the user to vary the template's usual behavior.'''''.  The usual behavior  suits most situations but the designer builds-in ways of changing things just in case.  Option values are usually limited to a short list so these are described in a template's documentation.  For example, option values for an option called ''align'' might include only ''left'', ''right'', or ''center'', and no others.  Templates do not ''always'' need options, since their default behavior is often enough.
*'''''DEFAULTS are the values used by a template when the user did not say'''''.  Default values are specified in design, and they could apply to formats or to user text inputs.  For example, in the alignment example above, if the ''align'' option was not used, the template could  use ''left'', provided that ''left'' had been specified in design as its default.  In the same way if the user forgets to type a text input, the template could use a pre-planned ''default'' input instead of the missing parameter; sometimes just a code to say something was forgotten. 
*'''''PARAMETERS are usually bits of text that a user enters for a template to process'''''.  For example, if a template makes text red, it still needs to know the text to color; this text is called a ''parameter'', and the text is included by the user when the template is ''called'' for use.  Sometimes parameters contain text like code to insert an image, or even a gallery or a table; it just depends what the template is designed for.  A template can even be the parameter of ''another'' template; for example, a template to insert a test paragraph might occupy the parameter space of a template to make a text box.  The new paragraph would then appear in a new text box.
*'''''MORE GENERALLY,''''' templates let us do much of the preparation in advance of making a page, and let us insert a block of typing, be it code to make tables, boxes, and other structures, or just a paragraph of text that is used a lot.


==Usage syntax==
==Usage syntax==
Line 43: Line 55:
Notice that the same double-brace syntax is used for many MediaWiki variables and parser functions (see [[Help:Magic words]]). For example, the code <code><nowiki>{{NAMESPACE}}</nowiki></code> may look like a template call, but it is actually a variable whose value is the namespace prefix of the current page.
Notice that the same double-brace syntax is used for many MediaWiki variables and parser functions (see [[Help:Magic words]]). For example, the code <code><nowiki>{{NAMESPACE}}</nowiki></code> may look like a template call, but it is actually a variable whose value is the namespace prefix of the current page.


==Usage hints and workarounds==
 
The following points may be worth noting when using templates:
* An unnamed parameter cannot contain an ordinary equals sign, as this would be interpreted as setting off a named parameter. (This does not apply if the equals sign comes within another template call or other item which the parser handles separately.) To pass an equals sign in an unnamed parameter (for example in a [[URL]] with key/value pairs), replace the equals sign with the special template {{tlx|{{=}}}}, which returns an equals sign that will not be specially interpreted. Another method is to replace the unnamed parameter (and any subsequent unnamed parameters) with named parameters&nbsp;— the first unnamed parameter is equivalent to a named parameter with the name "1", and so on. So to call template {{tl|done}} with the parameter "a=b", type either <code><nowiki>{{done|a{{=}}b}}</nowiki></code> or <code><nowiki>{{done|1=a=b}}</nowiki></code>.
* Similarly, it is not possible to use an ordinary pipe character | in template parameters, as it will be interpreted as a separator. (Again, this does not apply if it comes within another separately parsed item, such as a piped wikilink.) This time the problem can be solved by using the special template {{tlx|!}} in place of the pipe, or (if the pipe is not intended to be parsed specially at a higher level) using the [[List of XML and HTML character entity references|HTML entity]] <tt>&amp;#124;</tt>.
* Remember that whitespace characters (spaces, tabs, carriage returns and line feeds) are not automatically stripped from the start and end of unnamed parameters (as they are from named parameters). Including such characters (or any other non-visible characters in any parameters) may in some cases affect the template's behaviour in unexpected ways. (Template designers can use {{tl|StripWhitespace}} to remove unwanted whitespace in unnamed parameters.)
* In documentation and discussions it is often convenient to be able to produce the template call syntax, with a link to the template in question, but without actually calling the template. This can be done easily using the "{{tl|tl}}" template (the ''template link'' template). For example, using the text "<tt><nowiki>{{tl|tc}}</nowiki></tt>" produces "{{tl|tc}}". There is an extended version, {{tl|tlx}}, which also supports parameters.
* When a template is changed (when the template or one of its subtemplates is edited), the change will be reflected on all pages on which the template is transcluded. However the change may not become visible on all pages immediately&nbsp;— a previously cached version of a page, based on the previous version of the template, may continue to be displayed for some time. Use the [[Help:Purge|purge]] function to force a page to be displayed using the latest versions of templates. (This includes the template page itself, if it contains usage examples.)
* When viewing old versions of pages, remember that templates will be transcluded as they are now, not necessarily as they were when the old page version was active.
* To list all pages onto which a template is transcluded, use [[WP:What links here|What links here]] on the template page. (This will not include pages where the template has been substituted.)
* To get a list of templates transcluded on a page, click "Edit", and find the list below the edit window. This list also includes the sub-templates used by the templates that are directly transcluded. To get such a list for a page section, an old version of the page, or your newly edited version prior to saving, click "Show preview" on the appropriate edit page. (For an old version, the subtemplate tree will be constructed according to the templates' current state.)
* There are limits to the number and complexity of the templates that an article may have. See the "[[#Expand limits|Expand limits]]" section for help in resolving this.


==Creating and editing templates==
==Creating and editing templates==
Templates are created and edited in much the same way as any other page: choose an appropriate name, navigate to that page, then click the Edit tab or create a new page as needed. As mentioned above, templates are normally placed in the [[WP:Template namespace|Template namespace]], though templates intended for your own personal use or for experimentation can be created in your own [[WP:user space|user space]]. Anything that can be included on a normal page or article can be included on a template, including other templates (called ''subtemplates''). Templates often make use of programming features&nbsp;— parameters, parser functions and other [[Help:Magic words|magic words]]&nbsp;— which allow the transcluded content to vary depending on context. There are also special tags to control which information is transcluded and which is not.
Templates are created and edited in much the same way as any other page: choose an appropriate name, navigate to that page, then click the Edit tab or create a new page as needed. Templates intended for your own personal use or for experimentation can be created in your own [[WP:user space|user space]]. Anything that can be included on a normal page or article can be included on a template, including other templates (called ''subtemplates''). Templates often make use of programming features&nbsp;— parameters, parser functions and other [[Help:Magic words|magic words]]&nbsp;— which allow the transcluded content to vary depending on context. There are also special tags to control which information is transcluded and which is not.


Before creating a template, do a quick search for existing templates (e.g. by exploring [[Portal:Template index]]) to see if there's already a template that does what you want, or a similar template whose code can be copied and modified (or left in place and expanded). Look for generic templates on which the new template can be based (for example, [[WP:navbox|navbox]] templates can be easily created by calling the generic [[Template:Navbox]]).
Before creating a template, do a quick search for existing templates (e.g. by exploring [[Portal:Template index]]) to see if there's already a template that does what you want, or a similar template whose code can be copied and modified (or left in place and expanded). Look for generic templates on which the new template can be based (for example, [[WP:navbox|navbox]] templates can be easily created by calling the generic [[Template:Navbox]]).
Line 64: Line 66:
'''Be extremely careful when editing existing templates&nbsp;— changes made can affect a large number of pages, often in ways you might not expect.'''  
'''Be extremely careful when editing existing templates&nbsp;— changes made can affect a large number of pages, often in ways you might not expect.'''  


To propose the deletion of unused or inappropriate templates, or other changes in the way particular templates are used, go to [[WP:Templates for discussion|Templates for discussion]] (TfD).
===Handling parameters===
The values of the parameters which can be fed to a template are represented in the template code by items enclosed between ''triple'' braces:
* the code <code><nowiki>{{{xxx}}}</nowiki></code> will be replaced by the value of the parameter named ''xxx''
* the codes <code><nowiki>{{{1}}}</nowiki></code>, <code><nowiki>{{{2}}}</nowiki></code> etc. will be replaced by the first, second etc. unnamed parameter (or the value of a parameter named ''1'', ''2'', etc.); these are sometimes known as ''positional'' parameters
If a parameter is not assigned a value, then the above replacements will not take place&nbsp;— the form "{{{xxx}}}" will remain as the effective value of the parameter. To change this behaviour, define default values using the pipe syntax. For example, <code><nowiki>{{{1|default}}}</nowiki></code> will be replaced by the first unnamed parameter if there is one, or otherwise by the text "default". Similarly, <code><nowiki>{{{xxx|}}}</nowiki></code> will be replaced by the parameter named ''xxx'' if it exists, or otherwise will be left blank. Though if a template is called with the parameter specified as empty (e.g. <code>&#123;&#123;Example|&#125;&#125;</code>), the default for the parameter will be ignored; if that is undesired one can use <code><nowiki>{{#if:{{{1|}}}|{{{1}}}|default}}</nowiki></code> instead to get the text "default" even if the parameter is specified as empty.


Parameters do not get expanded when they are inside nowiki tags or XML-style extension tags. Thus, the following will not work within a template&nbsp;— <nowiki><myextension xparam={{{tparam}}}> ... </myextension></nowiki>&nbsp;— because the parameter is not expanded.


Because of the multiple uses of double-brace and triple-brace syntax, expressions can sometimes be ambiguous. It may be helpful or necessary to include spaces to resolve such ambiguity, for example by writing <code><nowiki>{{ {{{xxx}}} }}</nowiki></code> or <code><nowiki>{{{ {{xxx}} }}}</nowiki></code>, rather than typing five consecutive braces. However, watch out for unwanted whitespace appearing in template expansions.


===System variables and conditional logic===
===System variables and conditional logic===
Line 156: Line 148:
|}
|}


==Text Paragraphs==
*'''''TEMPLATES are just blocks of saved text that have been given names'''''Some are ordinary text paragraphs and some contain wikitext to make headings, indents, tables, and the like.  In a simple case, by typing a template's name in the work, an entire block of text is added to the page with all of its formats and other parts, just as if it had been typed by the userThis behavior can be repeated at any point that the user wants, and almost any work that is found on a wiki page could be placed within a template to do this.  The main effort as you might suppose, lies in its initial design.
The code for a template need not start with any special character or symbolThe main consideration is that the code performs the required action, just as if it were typed directly onto the pageAt the 'end of the code block, be sure to add the '''<nowiki><noinclude></noinclude></nowiki>''' tags as mentioned above.


*'''''NAMES of templates are assigned when they are first saved'''''. The '''name''' must be unique, and it is used when a template is ''called'' for useSometimes other text is also used along with the name; it can include any '''options''' and '''parameters'''.      
All of the existing Wikitext and HTML code that can be used in a page can be used for a text template.  The user of a page does not have access to the parts associated with styles, namely the heading of the web page and their style sheets.  As a result, users are limited to modifying the parts of the page that ''are'' available, the text within the body of the page. Those familiar with web page design will know that the only remaining available method is to modify the page's text with '''in-line styles'''.  Working methods use the '''<nowiki><div></div></nowiki>''' tags and the '''<nowiki><span></span></nowiki>''' tags, thanks to a feature of Wikitext that allows the use of HTML coding within it.  CSS, (Cascading Style Sheet), properties and values are used within these tags to modify the text styles that would otherwise apply.


*'''''OPTIONS allow the user to vary the template's usual behavior.'''''.   The usual behavior  suits most situations but the designer builds-in ways of changing things just in case.  Option values are usually limited to a short list so these are described in a template's documentation.  For example, option values for an option called ''align'' might include only ''left'', ''right'', or ''center'', and no others.  Templates do not ''always'' need options, since their default behavior is often enough.
    


*'''''DEFAULTS are the values used by a template when the user did not say'''''Default values are specified in design, and they could apply to formats or to user text inputs.  For example, in the alignment example above, if the ''align'' option was not used, the template could use ''left'', provided that ''left'' had been specified in design as its default.   In the same way if the user forgets to type a text input, the template could use a pre-planned ''default'' input instead of the missing parameter; sometimes just a code to say something was forgotten. 
====The Simplest Case====
Before doing any formatting, consider the method for making a template from a simple block of textType a block of text, with all of its formats and page layout in place, then save the block as a template. It is as simple as that.


*'''''PARAMETERS are usually bits of text that a user enters for a template to process'''''.  For example, if a template makes text red, it still needs to know the text to color; this text is called a ''parameter'', and the text is included by the user when the template is ''called'' for use.  Sometimes parameters contain text like code to insert an image, or even a gallery or a table; it just depends what the template is designed for.  A template can even be the parameter of ''another'' template; for example, a template to insert a test paragraph might occupy the parameter space of a template to make a text box.  The new paragraph would then appear in a new text box.


*'''''MORE GENERALLY,''''' templates let us do much of the preparation in advance of making a page, and let us insert a block of typing, be it code to make tables, boxes, and other structures, or just a paragraph of text that is used a lot.  The remainder of this introduction gives a  few examples to ''show'' what templates do on the page, and in the sections that follow will be found what is needed to modify and make new templates for use in writing Wikibooks.


<big>'''In the first example'''</big>, the template '''Caption''' is used.   It has two text parameters and no options at all.
==Making Boxes==
----
The following sections ''make'' box or table templates from Wikitext.  They can also be made with HTML tables in the same way.    When it comes to ''making'' such a template, wikitext is fine but when a table is needed to go ''into'' a template as its parameter, or part of its parameter, an HTML table should be used instead.


This is the code to call the template for use;
This [http://en.wikibooks.org/wiki/Editing_Wikitext WikiBooks text] touches on HTML table structures, and explains how to use styles.   
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{caption|This is the first parameter's text: | This is the second parameter's text}}</nowiki>}}
The result of doing so is to produce the text:
{{result|fs=1em|{{caption|This is the first parameter's text: | This is the second parameter's text}}}}
Notice that the template has formatted the text, and that each parameter was handled differently.  This template is used to make consistently formatted image captionsThe source code for the template ''Caption'' features little more than text formatting.


<big>'''In the second example'''</big>, the template '''Drop''' is used.  It has one text parameter and several options, none of which are needed here.
   
====The Box Structure====
Boxes are essentially ''tables'', in fact table cells.  The CSS property list to format  tables is extensive.  Simple boxes make use of the table ''container'', and one or two ''cells'' within it.


This is the code to call the template for use;
Apart from the table container, the other structures of a table include its ''rows'', and ''cells''.  In the case below there are two rows, each with only one cell in them.   Each part of a table has properties that affect it, and an example of typical table coding can be seen in the listing below.
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{drop|N}}</nowiki>otice that the template has inserted...}}
The result of doing so can be seen in the paragraph below.


{{drop|N}}otice that the template has inserted a drop capital from the single character used as a parameterThis template can be used to start sections within certain body textAgain, the source code for the template ''Drop'' is largely text formatting.
====Parameters and Options====
It is intended to provide three ''options'' along with the two ''parameters''The options are to be ''background'',''width'', and ''align''The parameter ''names'' are to be ''1'' and ''2'', with the labels ''heading'' and ''content''.


===Nesting templates===
Templates may contain other templates&nbsp;— this is usually called "nesting". As the template is processed, the wikitext produced by any nested templates is transcluded into the nesting template, so that the final product is essentially processed from the most deeply nested template out. While fairly straightforward in application, it involves some noteworthy quirks and tricks.


<big>'''The third example'''</big> uses template '''Dropimage''' to make a drop-box with an image in it.  This template has many options, but only two were needed; the ''width'' option, and the ''align'' option.  The other options use the defaults.  There are two parameters; the top caption ''Press to View'' and the contents, in this case the Wikitext code for an image.  The contents in the example can be viewed by clicking the arrow on the box.  
===Examples===
Here are two examples of box templates that are easy to use and are useful to those just starting out.


This is the code to call the template;
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{dropimage|width=150px|align=center|Press to View|[[image:Flower poster.jpg|600px]]<br>A Flower Poster}}</nowiki>}}
The result of doing so is:
{{dropimage|width=300px|align=center|Press to View|[[image:Flower poster.jpg|600px]]<br>A Flower Poster}}
{{-}}
The template for this example consists of code to build the box structure, and the image code is strictly its parameter, i.e., the item that it processes.


Whereas the ''detailed'' study of this subject is complex, it should become clear that using and making templates like those mentioned above is well within the abilities of most wiki writers.   Sadly, it is often the case that a writer sees the advantages of templates only when his work is nearly done, and a bit of effort in recognizing repetitive routine early in the work could save much time. Whenever a routine is repeated often, there is a job for a template.
<pre>
{{Box1 start}}
Sample text
{{Boxes end}}
</pre>
;gives...
{{Box1 start}}
Sample text
{{Boxes end}}
<pre>
{{Box1 start}}
Box1 text
{{Box2 start}}
Box2 text
{{Boxes end}}
</pre>
;gives...
{{Box1 start}}
First box text
{{Box2 start}}
Second box text
{{Boxes end}}


It is true to say that most templates in the wiki family of projects consist of either the formatting of text paragraphs or the making of boxes of some kind.   With this in mind the text below explains the process of template-making for text, boxes, and drop-controls. As preparation, those who intend to make box templates of any kind would benefit from an elementary knowledge of tables, and this knowledge is quickly available in the first few sections of the page [[Editing_Wikitext/Tables|'''Tables''']], where an introduction to CSS styles is also to be had.
===Making a Basic Wiki Table===
<pre>
{|class="wikitable"
! one box
|} </pre>
;gives...


==Finding and Using Templates==
{|class="wikitable"
There are already several thousands of templates within the WikiBooks templates namespace.  That is another way of saying that the templates list is already long.  At first sight, this may seem to avoid the need for template-making, but things are not so simple.
! one box
|}


If the ''name'' of the template is known, then it can be found easily, but if the name is ''not'' known, it can take a long time to find a template similar to the one that you are looking for.  Templates have their functions described on their own pages but many do not include notes, so the task of knowing which is which, and what they do even when they are found, becomes doubly difficult.
<pre>
 
{|class="wikitable"
Templates made in ''Wikipedia''  and ''Wikibooks'' are not interchangeable, since they exist on separate servers.  Although the code to make them is identical, this description applies to finding things in Wikibooks.   
!
 
!Top row
*To view lists of templates listed ''alphabetically'' within WikiBooks, follow the link to the [http://en.wikibooks.org/w/index.php?title=Special:AllPages&namespace=10 '''All Templates Namespace'''].
|-
*To find templates listed in various template ''categories'', for example, ''drop-control templates'', follow the link to the page [[:Category:Templates]].
!First row
*If you ''know'' a template's name, then find the template page by using the search box on any Wiki page.  For example, to find ''Dropimage'' just type;
| (add some txt)
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>Template:Dropimage</nowiki>}}
|}
then ''enter''.
</pre>
 
;gives...
When a template page is found, the code to make the template can be seen by viewing its editing window.  Many pages have their documentation on the same page as the template code, isolated from it with <nowiki><noinclude></noinclude></nowiki> tags.
{|class="wikitable"
 
!
If after searching, you still need to make a template, as many no doubt do, then read on.
!Top row
 
 
===Put it on the Page===
----
Templates are called for use in pages by typing a line of Wikitext, and so the user needs to know the correct spelling of the template's name, options, and parameters.  Even when these are known it is all too easy to disrupt a page with a template error, especially during trials, so consider using the [[WB:SB|'''sandbox''']] for testing.  Some templates have all of the documentation and details on the same page and this makes them easy to use.  See templates  [[Template:Plainlist|Plainlist]], and  [[Template:Codebits|Codebits]] as examples.
 
To ''call up'' any template for use in a page, '''the code is typed within double curly brackets'''. <nowiki>{{}}</nowiki>.   
Included within the curly brackets is the template '''name''', then, if required, a sequence of '''options''', followed by a sequence of '''parameters'''.  '''All entries are separated by ''pipe'' symbols'''. ('''<nowiki>|</nowiki>''').  For example, the general form to use for a template with two ''options'' and one ''parameter'' is as follows:
{{-}}
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{Name|Option1=Value|Option2=value|Parameter1}}</nowiki>}}
{{-}}
and a typical example of its use is:
{{-}}
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{Plainlist|width=250px|background=LightSalmon|The text for the box goes here.}}</nowiki>}}           
{{-}}
The above code has only ''one'' parameter; it is numbered '''1''' by default.  Parameters are given numbers or names to identify them in their design code, and examples will be seen in the sections that follow.  The template-call in the example uses a so-called ''unnamed'' parameter, because it is not preceded by a term like '''1=''' (numbered parameter),  or '''content=''' (typical named parameter).        When templates have ''several'' parameters then the parameter numbers or names help to make clear to the template which is which.  Alternatively, the template can manage with unnamed and unnumbered parameter entries provided that they are in any case listed in their correct number sequence.  When in doubt, use names or numbers.  At times, especially when the first character of a parameter is a symbol, the use of named or numbered parameters avoids the corruption that would otherwise result with the unnamed entry.
 
'''The sequence of <u>''options''</u> is ''unimportant''''', since '''all options must be named''' in any case.  Using ''named'' values just means adding the name of the option and an equals sign before the option's ''value''.  This of course requires a knowledge of the template's details.
 
'''''Template'' names are sensitive to case except for the first letter''', so a useful convention is to use lower case for template name, parameters, and options all of the time; that way you will never be in doubt.
 
'''''Parameter'' names are quite sensitive to case in every way''', so a capital letter makes all the difference.   As a general rule, do not mix ''unnamed'' and ''named'' parameters in a template call, since the method used by the program to interpret their meaning becomes confused.  Either use ''all unnamed'' with special attention to their sequence, or ''all named'' in any order that you like.
 
===Find Details from Code===
----
Let us assume that a template made by others has been found but that its details are unclear.  Even without much knowledge of mark-up, it is usually possible to discern the options and parameters of a template by inspection of its coding.  To see how this can be done follow the reasoning below.
 
The coding and anything else on a template page can be displayed in the sandbox by typing a special code there.  The template does not do anything when this is done; it just reveals the text of the template page.  That is, it reveals the coding and any documentation.  As an example the template code for say, the template '''Tocbox''', can be viewed in the Sandbox by typing:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{msgnw:tocbox}}</nowiki>}}
To save the reader the trouble of doing so here, the template code for '''Tocbox''' is given below.
{{-}}
 
'''Code for the Template Tocbox'''<br>
<table cellpadding=20px style="font-family:courier;border:1px dashed blue;background:#f9f9f9;;">
<td align=left><poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki>{| class=toccolours style="margin:1em 0 0 0;width:{{{width|300px}}};" align={{{align|left}}}
| align=center style="font-weight:bold;"|{{{Heading|{{{1}}}}}}
|-
|-
| align=left style="font-weight:normal;"|{{{Content|{{{2}}}}}}
!First row
| (add some txt)
|}
|}
<noinclude>
</nowiki></poem></td>
</table>


{{-}}
<pre>
The template page itself has a good description for its use, but assume for a moment that the descriptive material was absent.  The code at the top of a template page is ''always'' the template source code; consider the example given above.  Although it looks complicated, the object here is ''not'' to understand it, but to find the options and parameters from the code itself.
{| class="wikitable"
 
!top row
Note that the end of the code is marked with a <nowiki><noinclude></nowiki> tag, to make sure that any text that follows it is not used as a part of the template.  In this example, there are ''two'' parameters; they can be recognized as the items with the form:
!This is text
 
!This is more txt
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{{heading|{{{1}}}}}}  and  {{{content|{{{2}}}}}}</nowiki>}}
!This is more txt
 
|-
These entries identify '''parameters''' ''one'' and ''two'' respectively.  It is clear, even without much understanding, that the first parameter is the ''heading'' text and the second parameter is the ''content'' text, and these terms in addition to the numbers could be used as their names .  In the event that a user forgets to enter the parameter for say, ''content'', a '''{{{2}}}''' will be displayed on the page as a reminder of what is missing.
!line1
 
|(add some txt)
All of the '''options''' within this template are recognized from the typical form;
|(add some txt)
 
|(add some txt)
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{{align|left}}}</nowiki>}}
|-
 
!line2
This extract states that there is an option called ''align'' that has the default value of ''left''.  The idea of this default is that the value '''left''' would be used for ''align'' if the user does not use that option in the template call. The option could have almost ''any'' name; in fact it has been given the same name as the '''HTML attribute''' associated with it, (the part before the equals sign in the main code block).  There are several properties within this code but only two of them have been coded as options; ''align'' and ''width'', and both options have similar bracket formats to that of the above example.
|(add some txt)
 
|(add some txt)
With the options and parameters now understood, test the template on a page as follows:
|(add some txt)
 
This is the code:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{tocbox|align=center|width=300px|Heading text|Content paragraphs}}</nowiki>}}
The result is:
{{tocbox|align=center|width=300px|Heading text|Content paragraphs}}
 
It should by now be clear that despite having no specification for the template in the first instance, it has been possible to obtain information from the coding for its use.
 
 
 
===Modifying a Template===
----
Assume for a moment that a template has been found that is ''nearly'' right, but not quite.  Say for example that the background color was the only part that was wrong.  The source code for such a template could be changed, by adding a term to modify its background color.  Then, the ''modified'' version could be saved as a new template, with a different name.  Note that if the modified template were saved with the ''same'' name as before, the existing users who depended on the original colors would experience unwelcome changes in their work.
 
There is another way that allows the new user to choose colors while the existing users can continue to enjoy the default colors that their work displays.  The template can keep the old name if the background property is made into an option, and the original background color made its default.  Then, since the old users would not bother to specify the background color, perhaps not even knowing that they now ''could'', they would get the usual color as the default value and would be happy with it.  The new users who need a ''different'' color, could simply specify it as an option value when they call the template for use.  In this way both parties would be content.
 
The modifying of a template approaches the difficulty of ''making'' a new one at times, and this process is covered in other sections below.  For the background-change case, a suitable '''modified Tocbox''' code module would look like this.
The code is:
<table cellpadding=20px style="font-family:courier;border:1px dashed blue;background:#f9f9f9;;">
<td align=left><center>Code for a Modified Template Tocbox</center><br><poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki>{| class=toccolours style="margin:1em 0 0 0;width:{{{width|300px}}};background:{{{background|#f9f9f9;}}};" align={{{align|left}}}
| align=center style="font-weight:bold;"|{{{Heading|{{{1}}}}}}
|-
|-
| align=left style="font-weight:normal;"|{{{Content|{{{2}}}}}}
!line3
|(add some txt)
|(add some txt)
|(add some txt)
|}
|}
<noinclude>
</pre>
</nowiki></poem></td>
;gives...
</table>
{{-}}
In the above code the ''background'' property has been made into an option.  In addition, the original background color, '''#f9f9f9;''' , (light gray), has been used for the default.   To labor the point, if the user does not bother to specify the background color, he will still get the ''gray'' color as before.   Note again that the added option need not have been called ''background'' but could, for example, have been called ''bgc'' or some other name.  In that event the template's option code would look like '''<nowiki>background:{{{bgc|#f9f9f9;}}}</nowiki>''', and another color would then be called using say, '''<nowiki>bcg=papayawhip</nowiki>''' on the page.


The real template '''Tocbox''' has not been modified here, though this example provides a reliable demonstration of the method to use for doing so.  After the modification above the template could be called by the new users as follows:
{| class="wikitable"
 
!top row
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{tocbox|align=center|width=250px|background=papayawhip|Heading|Long text paragraphs}}</nowiki>}}
!This is text
 
!This is more txt
A knowledge of CSS property values allows considerable variation in a template's appearance.  Luckily, the subject is well documented.  See the external ''W3'' site's [http://www.w3schools.com/css/css_reference.asp '''CSS Reference List'''] for a comprehensive listing of values and properties.  Although the examples on the referenced page are designed for style sheets, the syntax found there is also that used for modifying styles within templates and other in-line styles.  In addition, a useful color reference can also be had at [http://en.wikipedia.org/wiki/Web_colors '''Web Colors'''].  A drop-box with many of the CSS properties for tables has been provided in the box-making section below. If time is short it could be noted that most of the template work done so far in this project, (WikiBooks that is), could have made do with little more that the CSS properties of text and tables.    Study of these two areas is thus rewarding.
!This is more txt
 
|-
CSS reference sources are useful, though styles can also be changed with ''HTML attributes'', (the styles like ''align'' with the ''equals'' signs).  Such attributes can be seen in HTML reference texts as opposed to CSS texts, and in the aforementioned drop-box below.  It may be of interest to know that some HTML attributes are the only ways to accomplish certain tasks;  examples include ''colspan'' (to span table columns), ''rowspan'' (to span table rows), and ''align'', (to align tables to center, something that the CSS ''float'' property cannot do).
!line1
 
|(add some txt)
 
|(add some txt)
 
|(add some txt)
==Making Templates==
|-
There are many template types, but those used for inserting and modifying text are the most numerous.  Boxes feature next; whether they are ''information boxes'', so-called ''user boxes'', or simple ''text boxes'', they all have common constructs.  Some templates have dynamic functions, like drop-controls, though once their basic outlines are clear, they can be shaped for many purposes.  At least one example of each will be considered.
!line2
 
|(add some txt)
Template making consists of writing functional code, Wikitext or HTML, or sometimes a mixture of both.  The method is to test the code in the Sandbox, until the function works well.  Then the options and the parameters can be assigned to the code.  These are tested again, and if all is well, the block of code can be saved as a template.
|(add some txt)
 
|(add some txt)
In saving the template it as well to check whether or not there is an existing template of that name already.  The simplest way to save a template is as follows.  First, make sure that you are logged-on in a page of '''WikiBooks''', to avoid making a template in the wrong project.  Go to the ''search'' box at the left of the WikiBooks page, and enter the wording to find the as-yet unmade template.  Assume here that the intended name is to be '''Caption'''.  The line to type in the search window is just:
 
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>Template:Caption</nowiki>}}
 
If the template is found, then the name is already taken, and another is needed.  Assuming that the name is not found, then the search results window will state that it was not found and ask whether or not you want to ''make'' the page.  Click the link to make the page.
 
The link opens a template editing page with the name of the template already listed as its address.  Copy the code from your work in the sandbox, then paste it into the empty template page.  In the line immediately following the last line in the code block, add the tags '''<nowiki><noinclude></noinclude></nowiki>'''.  All text not intended to be a part of the template code, must be placed ''between'' these tags, as is the case for the template's description.
 
Finally, save the page by pressing the ''Save page'' button at the bottom of the page.  The template is now made, and can be called into use with its given name.  Go to the sandbox and test the features of the template. 
 
 
 
===Text Paragraphs===
The code for a template need not start with any special character or symbol.  The main consideration is that the code performs the required action, just as if it were typed directly onto the page.  At the 'end of the code block, be sure to add the '''<nowiki><noinclude></noinclude></nowiki>''' tags as mentioned above.
 
All of the existing Wikitext and HTML code that can be used in a page can be used for a text template.  The user of a page does not have access to the parts associated with styles, namely the heading of the web page and their style sheets.  As a result, users are limited to modifying the parts of the page that ''are'' available, the text within the body of the page.  Those familiar with web page design will know that the only remaining available method is to modify the page's text with '''in-line styles'''.  Working methods use the '''<nowiki><div></div></nowiki>''' tags and the '''<nowiki><span></span></nowiki>''' tags, thanks to a feature of Wikitext that allows the use of HTML coding within it.  CSS, (Cascading Style Sheet), properties and values are used within these tags to modify the text styles that would otherwise apply.
 
It is as well to point out here the difference in use for '''<nowiki>span</nowiki>''' and '''<nowiki>div</nowiki>''' in text templates.  '''<nowiki>Span</nowiki>''' should be used to format text only, noting that any formats applied to the text will not extend beyond the last text character; '''<nowiki>div</nowiki>''', on the other hand, will apply its formats to a rectangular block of text that extends across the page.  the significance of this is that '''<nowiki>div</nowiki>''' is neater for changing background colors on the page.  A comparative example can be seen in the ''Classes and Styles in Tags'' section of [[Editing_Wikitext/Class_and_Style_Notes|'''Class and Style Notes''']]. 
 
 
====The Simplest Case====
Before doing any formatting, consider the method for making a template from a simple block of text.  Type a block of text, with all of its formats and page layout in place, then save the block as a template.  It is as simple as that.  Such blocks of text find use for test text, such as [[Template:Lorem_ipsum|'''Lorem Ipsum''']], a well-known text block of fictitious content used by printers and others in laying out their work.  To use such a template just type:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{lorem ipsum}}</nowiki>}}
at any convenient place on a page to produce the text block.  This block of text is not pre formatted with hard breaks, so it will ''wrap'' within the space where it is typed, and with the ''default'' text styles of the page.   
 
 
====Adding Styles====
To ''modify'' text styles, for example, for the text '''This is the text''', we first place the text within <nowiki><span></span></nowiki> tags, like this:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki><span>This is the text</span></nowiki>}}
Then we construct a style statement ''within'' the first tag.  This example makes the font ''Garamond'', 20 points, colored red.  It looks like this:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki><span style="font-family:Garamond;font-size:20pt;color:red">This is the text</span></nowiki>}} 
and the result will be:
 
<center><span style="font-family:Garamond;font-size:20pt;color:red">This is the text</span></center> 
{{-}}
Notice that there is still a closing arrow for the first tag; it is located at the end of the style statement.
 
Notice also that there are three style rules in the statement, separated by semi-colons; these are ''font-family:Garamond'' to set the ''face'' of the font, ''font-size:20pt'' to set the ''size'' of the font, and ''color:red'' to set the ''color'' of the text.
 
The style statement starts with the term ''style='', and the right hand side of the statement is entirely within double quotes.
 
The individual style rules consist of a ''property''; the left part, and a ''value''; the right part.  The two parts are ''separated'' by a full colon.  The format of a style statement is strict.  If the format has an error within it then the whole statement could fail.  Note that Wikitext ''could'' have been used on the text itself; for example, to produce italics, (double quotes), or text that is bold, (triple quotes).  Wikitext acts in ''addition'' to the CSS styles, provided that there are no obvious conflicts.  Several spans and style statements can be applied to produce quite complex results.
 
These tag sets can be ''nested''; that is, one set of tags within another set.  Beware of nested '''span''' tags, since there can be unexpected results.  Say that an overall style is applied to several paragraphs using span tags.  Within these paragraphs ''another'' span set is used to format one of the paragraphs differently.  When this is viewed, at the point where the ''inside'' span closes, the styles will have reverted to the body text styles described by the style sheet, and not the intended outside style definition.  This is perhaps because the first closing tag was wrongly interpreted as the end tag.  The problem is '''avoided by using div tags for both''', or at most by '''using span tags for only one of the formats'''.   
 
Many properties exist to modify text.  They consist of all of the text styles found in style sheets, namely those for fonts, padding, alignment, margins, borders, text colors, and backgrounds. [http://www.w3schools.com/css/css_reference.asp '''CSS property lists''']  and other material on [[CSS_Programming/Fonts_and_Text|'''Fonts and Text''']] provide the source material for all such work.  Although CSS properties and examples are listed primarily for style sheets, the properties and values ''themselves'' can be used on the page and in templates.  The Study Work drop-box contains a useful code module for studying text properties.  It contains most of the useful text entries and can be copied for study into the [http://en.wikibooks.org/w/index.php?title=Wikibooks:Sandbox&action=edit '''sandbox'''].   
{{-}}
{{dropimage|align=center|cbgc=lightyellow|hbgc=lightyellow|Study Work|<b>This module contains most of the useful text properties.  Copy it into the sandbox to experiment with text property values.</b><br><pre><div style="font-family:lucida handwriting;font-weight:bold;font-style:italic;font-size:12pt;color:blue;background:papayawhip;word-spacing:0pt;letter-spacing:0pt;line-height:1.8em;border:1px solid red;margin:10pt 100pt 10pt 50pt;padding:10pt 20pt 15pt 20pt;text-align:justify;"><center>Text Property Notes</center>
 
Both PADDING and MARGIN style-rule values use the sequence TOP, RIGHT, BOTTOM, then LEFT, i.e. clockwise starting at the top.
 
BORDER uses the sequence BORDER-WIDTH, BORDER-STYLE, then BORDER-COLOR for all of the four borders at once.  Other properties can address the four separately.
 
PADDING is the space around the text.  MARGIN is the space around the text block.  BORDER is the line that surrounds the text and its padding.
 
The code block contains the common text properties.
 
Experiment with the settings. </div></pre>}}
{{-}}
{{dropimage|hbgc=lightyellow|align=center|Color Values for Study Work|[[image:pastelsRGB.jpg|911px]]<br><br>Color values for CSS properties taking a form such as : Background:RGB(255,202,149)}}
{{-}}
 
 
====Parameters====
Now, continue to make use of the ''red-text'' example.  Although the code could be saved as a template just as it is, it would not be very useful since it consists only of fixed text.  To introduce the notion of ''variable text chosen by the user'', we need to make the text position in the code into a ''parameter''. 
 
Assuming that the basic code works correctly, the ''parameter'' brackets can be added.  In the above text example there is only ''one'' parameter, the content to be formatted.  Starting with the code above, just replace the text part so that the code line now looks like this:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki><span style="font-family:Garamond;font-size:20pt;color:red">{{{content|{{{1}}}}}}</span></nowiki>}}
Notice that the original text has now been replaced with:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{{content|{{{1}}}}}}</nowiki>}}
The ''digit'' identifies the parameter as number one.  It is also the ''name'' of the parameter.  The word ''content'' is just a convenient label, though either the number or the label can be used for ''named parameters''.  If the user forgets to write any text in a parameter position, then the number of the parameter will appear on the page to remind of it.  If the template had ''more'' than one parameter, a similar process could be applied, with a sequence of digits 2,3,4 etc., and adding a suitable label in place of ''content'' for each.
 
Saving it in the usual way completes such a template. Assuming that the template were to be saved with the name ''BigText'' then the entry to call it for use would be just:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{BigText|1=This is the text to format}}</nowiki>}}
Note that when a template has ''several'' parameters, the ones used can either be entered as ''named parameters'', using the number or label with an equals sign, or as ''unnamed parameters'', by omitting the added names and just entering the text directly.  The parameters should be ''all unnamed'' or ''all named'' but not a mixture of the two.  If they are ''unnamed'', the correct sequence must be maintained, and if they are ''named'', then ''any'' sequence can be used. Number names and label names ''can'' be mixed without difficulty in a template call.
 
Although virtually ''any'' tags can be modified by adding a style statement to the leading tag, it is not to say that the work can always be made into a template.  There is at least one exception that exists when it comes to making such a template.  The '''&lt;pre&gt;&lt;/pre&gt;''' tags by their very definition cause a template's parameter code to be disregarded, and a different approach is needed. Instead of attempting to make a modified pre-formatted text template consider the use of [[Template:Prettypre|Prettypre]] for a ready-made fancy version of these tags. 
 
That is to say, it is possible to modify the '''&lt;pre&gt;&lt;/pre&gt;''' tags with inline styles, to make more interesting pre-formatted text, and it is possible to add the tags to text used as a template's parameter, but making a template from text ''bounded'' by pre-formatting tags will prove more difficult.
 
 
====Options====
For completeness, we can also add ''options'' to our basic ''red-text'' template example.  Say we want to change the color of the text from time to time in our work.  We could make another complete template for the new color or we could just add an option to the text coloring code.  The new code looks like this:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki><span style="font-family:Garamond;font-size:20pt;color:{{{tint|red}}}">{{{content|{{{1}}}}}}</span></nowiki>}}
 
Note that the entire property value (applies also to an attribute value), must be enclosed in triple curly brackets.  Additionally, the value should be replaced with an ''option name / default value'' combination. In this case, if the user does not specify the color of text, it will be ''red'' in any case.  If it is specified, (see the example below}, it can be changed to any color using the option ''tint='' within the template call.  Assuming that this template's name were ''BigText'' the template call for purple text would be, say:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{BigText|tint=purple|1=My purple text goes here}}</nowiki>}}       
 
Other options could be made in the same way, and similar techniques could be used regardless of the tags used for the template.
 
A knowledge of the different tags and access to lists of CSS properties allows considerable scope in template design.
 
 
 
===Making Boxes===
----
The following sections ''make'' box or table templates from Wikitext.  They can also be made with HTML tables in the same way.    When it comes to ''making'' such a template, wikitext is fine but when a table is needed to go ''into'' a template as its parameter, or part of its parameter, an HTML table should be used instead.  The WikiBooks text [[../Tables|'''Making Tables''']] touches on HTML table structures, and explains how to use styles.  It is assumed that the reader is familiar with these concepts in the text that follows.
 
   
====The Box Structure====
Boxes are essentially ''tables'', in fact table cells.  The CSS property list to format  tables is extensive.  Simple boxes make use of the table ''container'', and one or two ''cells'' within it.
 
Apart from the table container, the other structures of a table include its ''rows'', and ''cells''.  In the case below there are two rows, each with only one cell in them.  Each part of a table has properties that affect it, and an example of typical table coding can be seen in the listing below.
 
<table cellpadding=20px style="font-family:courier;border:1px dashed blue;background:#f9f9f9;;">
<td align=left><poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki>{|style="background:lightyellow;width:150px;margin:none;border:1px solid lightgrey" align=left
|-
|-
| style= " text-align: center; padding: 5px 0 0 0"|'''Heading'''
!line3
|- style="text-align:justify;"
|(add some txt)
| style="padding:0px 10px 10px 10px;"|Content.
|(add some txt)
|(add some txt)
|}
|}
</nowiki></poem></td>
<pre>
</table>
{| class="wikitable" style="float: right;: 1em auto 1em auto;"
{{-}}
|+ '''(this is my table name)'''
Running this code in the sandbox produces the following:
! scope="col" | top row
{{-}}
! scope="col" | This is text
{| style="background:lightyellow;width:150px;margin:none;border:1px solid lightgrey" align=left
! scope="col" | This is text
|-
| row 1  || (add some txt) || (add some txt)
|-
|-
| style= "text-align: center; padding: 5px 0 0 0"|'''Heading'''
| row 2 || (add some txt) || (add some txt)
|- style= "text-align:justify;"
| style= "padding:0px 10px 10px 10px;"|Content.
|}
|}
{{-}}
</pre>
;gives...


If necessary, refer to the WikiBooks text [[../Tables|'''Making Tables''']] or the Wikipedia text [http://en.wikipedia.org/wiki/Help:Table '''Help-Table'''] for detailed advice on making tables.  Refer also to the drop-down box below for a listing of the commonly used table properties and their meanings.
{| class="wikitable" style="float: right;: 1em auto 1em auto;"
{{tablestyles}}
|+ '''(this is my table name)'''
{{-}}
! scope="col" | top row
For now, it will suffice to note only that:
! scope="col" | This is text
*A table is enclosed in these symbols: '''<nowiki>{| |}</nowiki>'''
! scope="col" | This is text
*A caption placed above the table starts with a '''<nowiki>|+</nowiki>'''.
|-
*A heading cell within the table starts with a '''<nowiki>!</nowiki>'''
| row 1 || (add some txt) || (add some txt)
*A new row is created with the symbols: '''<nowiki>|-</nowiki>'''
|-
*A data cell within a row is created with the symbol: '''<nowiki>|</nowiki>'''
| row 2 || (add some txt) || (add some txt)
*Style statements can exist at the table, row, or cell levels.
|}
*An additional pipe symbol separates a cell's styles from its text.''' <nowiki>|</nowiki>''' 
<Br>
*Starting tables, rows and cells on new lines avoids many problems in templates.
If you float the wikitable right, you can make your text rap around the box without leaving large blank spaces on your page. This is often very useful.
 
<Br>
Follow the reasoning in this description from the code.
<center> (This is how a line would look.)</center>  
 
The table container has ''background'', ''width'', ''margin'', and ''border'' properties, and the ''align'' attribute assigned.
*''Background'';sets the background color for the whole table.
*''Width''; sets the overall width of the table.
*''Margin''; removes margins of the table.
*''Border'': Sets the thickness, type, and color of the table border, all in one.
*''Align'': Permits the box to be placed on the page at ''left'', ''right'', or ''center''.   
 
 
The cell in the first row has ''text-align'',''padding'', and a form of heading text.
*''Text-align'';positions the cell text horizontally at the center.
*''Padding''; sets the padding within the first cell for the box heading text.
*''The Heading Text''; is made bold with Wiki mark-up.
 
 
The next row has ''text-align''.  This property applies style to all of the cells in the row at once, though not all properties can do this.
*''Text-align'';justifies text in the bottom cell - the main content.
 
 
The ''content'' cell has ''padding'', and the content text.
*''Padding'';sets the spacing around the content text.
*''The content text''; is the main text for the box template.   
Other properties could be specified for this text box, for example, for the details of the fonts to use, but there is enough here for this example.
 
 
====Parameters and Options====
It is intended to provide three ''options'' along with the two ''parameters''.  The options are to be ''background'',''width'', and ''align''.  The parameter ''names'' are to be ''1'' and ''2'', with the labels ''heading'' and ''content''.
 
The options and parameters have been added to the code below:
 
<table cellpadding=20px style="font-family:courier;border:1px dashed blue;background:#f9f9f9;;">
<td align=left><poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki>{|style="background:{{{background|lightyellow}}};width:{{{width|150px}}};margin:none;border:1px solid lightgrey" align={{{align|left}}}
| style= " text-align: center; padding: 5px 0 0 0"|'''{{{Heading|{{{1}}}}}}'''
|- style="text-align:justify;"
| style="padding:0px 10px 10px 10px;"|{{{Content|{{{2}}}}}}
|}</nowiki></poem></td>
</table>
{{-}}
'''Parameters''' have been made in place of the ''heading'' and ''content'' text.   The formats for parameters one and two are:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{{heading|{{{1}}}}}} and {{{content|{{{2}}}}}}</nowiki>}}
{{-}}
Each parameter format consists of a parameter ''label'',( ''heading'' or ''content''), a ''pipe'',  symbol,'''<nowiki>|</nowiki>''', and the true ''name'' of the parameter, (''1'' or ''2'').  In each case, both the parameter name ''and'' the entire parameter expression are enclosed in triple curly brackets. '''<nowiki>{{{}}}</nowiki>'''.


'''Options''' have been made for the properties ''background'', ''width'', and ''align''.  The formats are :
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>background:{{{background|lightyellow}}}  width:{{{width|150px}}} and align={{{align|left}}}</nowiki>}}
{{-}}
Notice that the format of the bracketing is similar to the examples given in the making of text templates, and that the same strict format is used to identify the options and parameters.
'''A parameter can use the ''option'' format too'''.  When a parameter does so, it must use the ''named'' parameter style in the template call.  The advantage of such a parameter is that it can have ''any'' default value, including an image.  The disadvantage of using the ''option'' format for a ''parameter'' is that the highly conspicuous numbered reminder is lost.  You will recall that the more formal parameter style gives a parameter number as the default.
The template can be saved in the usual way.  Assuming that the template were saved with the name ''Textbox'', then it could be called for use by typing the following:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{textbox|background=lightgrey|width=325px|align=center|Heading text here|Content text here}}</nowiki>}} 
The variations in boxes are considerable.  By adjusting the table structure, it is possible to add images and other effects.  Most of the information boxes within Wikipedia and WikiBooks have a table basis for their construction.
===Making Drop Controls===
----
----
Drop-boxes save space on the page and can be used for both text and for images.  Within Wikibooks these boxes are dynamic, and clicking the link on the heading of such a box drops it  box to show the entire contents section.  Clicking the link again restores it to its closed state.
Drop-boxes can be created in two ways. In the past, the way to make them was to use the classes ''NavFrame'', ''NavHead'', and ''NavContent''. These days, the ''collapsible'' class can be used for both tables and div boxes, its simplicity has made it a clear choice in the making of drop-boxes. The first section describes briefly the layout for collapsible divs. The remainder of the section is devoted to the version based on the collapsible table; this method is the basis of the ''ready-made'' drop-control template [[Template:Dropimage|'''Dropimage''']].


A ready-made template exists for a quite adaptable drop-box; it is [[Template:Dropimage|'''Dropimage''']], though for those who want the details, they are to be had at [[Editing_Wikitext/Tables#Sorting_and_Hiding|'''Sorting and Hiding''']]. 
<Br>


====Collapsible Boxes====
==External Links==
The basic code for drop-boxes is just:
*[http://creativecommons.org/licenses/by-sa/3.0/ Creative Commons Attribution-ShareAlike License]


{{block|ff='Courier New', Courier, monospace|fs=1.1em|ta=left|background=ivory|<poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki><div class="collapsible">
*[http://en.wikipedia.org/wiki/ Some parts of this page have been adapted from wikipedia]
<div class="title">Title</div>
<div class="body">
Hideable content
</div>
</div></nowiki></poem>}}


The above code produces a drop-box that extended across the whole width of the page. ''collapsible'' contains the other two sections, ''title'' refers to the panel with the link, and ''body'' refers to the text box within the drop box itself.
By default, the contents is hidden when the page is loaded. To have the contents shown by default, the user adds "selected" to the class declaration.  CSS styles could also be added as shown below and the option-brackets and parameter-brackets for template-making have been shown, as was explained in the previous section:
   
   
{{block|ff='Courier New', Courier, monospace|fs=1.1em|ff='Courier New', Courier, monospace|fs=1.1em|ta=left|background=ivory|<poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki><div class="collapsible selected" style="color:{{{color|darkgray}}}; width:{{{width|300px}}}; {{#switch:{{{align|center}}}|center=margin:auto;|left=float:left;|right=float:right;}}">
<div class="title" style="font-weight:{{{bold|bold}}};">{{{Heading|{{{1}}}}}}</div>
<div class="body" style="background-color:{{{background|lightyellow}}};color:{{{color2|black}}}">
{{{Content|{{{2}}}}}}
</div>
</div></nowiki></poem>}}
Changes in layout is obtained by changing styles in any of the sections, but the preferred method, using collapsible tables, is described in the next section.
====Collapsible Tables====
(currently being rewritten to update for collapsible tables)
The panel below shows the HTML and Wikitext code versions of a fairly basic drop-box based on the ''collapsible'' box class.  The two versions are equivalent, though users who intend to make a template should use the HTML version, since it can have a table as its content without any instability.  Nesting tables in Wikitext is problematic.
{{block|ff='Courier New', Courier, monospace|fs=1.1em|ta=left|background=ivory|
'''HTML Collapsible Table Cell'''
<poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki>
<table class="collapsible" style="border:1px solid black; width:300px;" cellpadding="5px">
<tr>
  <th style="text-align:center;">Any Heading</th>
</tr>
<tr>
  <td>Content cell text, images or HTML tables</td>
</tr>
</table>
</nowiki></poem>
'''WIKITEXT''' Collapsible Table Cell
<poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki>
{| class="collapsible" style="border:1px solid black; width:300px;" cellpadding="5px"
|-
! style="text-align:center;" | Any Heading
|-
|  Content cell text or images only
|}
</nowiki></poem>
}}
If, instead of the ''collapsed'' state, the ''selected'' state is needed on opening the page, then just add the class ''selected'' as in the line ''class="collapsible selected" ''.  The default state is ''collapsed'' which need not be added.
The ''width'' style in the table line sets the ''initial'' width of the table on the page, and with the exception of un-formatted text, the table will expand on opening to accommodate the contents.
The ''float'' and ''align'' attributes should be avoided for tables because browsers may not support table alignment. Tables can be aligned in a way compatible with most browsers by setting the initial width of the table to 100%, and by wrapping the table inside a div box with its width set to the desired width. For left and right alignment use float on the div box. For center alignment use a margin of auto on the div.
{{block|ff='Courier New', Courier, monospace|fs=1.1em|ta=left|background=ivory|
'''HTML Collapsible Table Cell'''
<poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki>
<div style="width:300x; {{#switch:{{{align|center}}}|center=margin:auto;|left=float:left;|right=float:right;}}">
<table class="collapsible" style="border:1px solid black; width:100%;" cellpadding="5px">
<tr>
  <th style="text-align:center;">Any Heading</th>
</tr>
<tr>
  <td>Content cell text, images or HTML tables</td>
</tr>
</table>
</div>
</nowiki></poem>
'''WIKITEXT''' Collapsible Table Cell
<poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki>
<div style="width:300x; {{#switch:{{{align|center}}}|center=margin:auto;|left=float:left;|right=float:right;}}">
{| class="collapsible" style="border:1px solid black; width:100%;" cellpadding="5px"
|-
! style="text-align:center;" | Any Heading
|-
|  Content cell text or images only
|}
</div>
</nowiki></poem>
}}
====Parameters and Options====
The parameter and option brackets are shown in the panel below for an HTML version of the drop-box template, and it will be noted that the method is similar to that used for simple tables in an earlier section.  It may be of interest to note that the outermost table is there simply to allow centering of the entire structure, since the ''collapsible'' class does not support it.
{{block|ff='Courier New', Courier, monospace|fs=1.1em|ta=left|background=ivory|
'''A Basic Drop-Box Template Coding'''
<poem style="font-family:'Courier New', Courier, monospace; font-size:1.1em;"><nowiki>
<table style="border:none; align={{{alignT|left}}}">
<tr><td>
<table class="collapsible" style="border:{{{border|1px solid black}}}; width:{{{width|300px}}}; background:{{{backgroundT|transparent}}};"  cellpadding="{{{padding|5px}}}">
<tr>
  <th style="background:{{{backgroundH|transparent}}};text-align:center;">{{{heading|{{{1}}}}}}</th>
</tr>
<tr>
  <td style="text-align:{{{alignC|left}}};"> {{{content|{{{2}}}}}}</td>
</tr>
</table>
</td></tr>
</table>
<noinclude>
All other template page material goes between these tags.
</noinclude>
</nowiki></poem>
}}
{{clear}}
The above HTML block of code has been saved as the template ''dropthing'', [[Template:Dropthing|'''Dropthing''']], and it can be called for use on a page by typing something along the lines of the following:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{dropthing|backgroundT=mistyrose| alignT=center|width=400px| Press to View|[[image:Hawthorn blossom.jpg|400px|thumb|center|''Hawthorn in bloom''.]] }}</nowiki>}} 
The drop-box that is produced with this template call is this:
{{dropthing|backgroundT=mistyrose|alignT=center|width=400px| Press to View|[[image:Hawthorn blossom.jpg|400px|thumb|center|''Hawthorn in bloom''.]] }}
{{-}}
A more complex ready-made template called [[Template:dropimage|'''Dropimage''']] exists for those who need it.  It has a large set of individual options, and the facility to add more properties and classes, the coding for which is described next.
===Advanced Options===
Although the user is always limited by the original template's design, he has some latitude afforded by the pre-planned options.    There is a way, however that allows the user to add  classes and CSS properties not considered in the original design.  For this method to work the designer of the template must anticipate the possible future need for such a change, and add a few extra keystrokes.  It is explained below. 
Because both ''class'' and ''style'' declarations are themselves HTML ''attributes'', in the same way as ''align'', ''cellpadding'', and many others, these two can also be made into options.
====Add Classes====
To allow user-changes to the classes for the above drop-table template, the class declaration (expression) line needs to modified as follows:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>class="{{{class|collapsible}}}"</nowiki>}} 
This has the effect of making a new option called ''myclass'' that has a default value of ''collapsible''; that is, if no ''myclass'' option is written by the user the default will apply.  Now, having modified the class-declaration, the user could change the class ''on-the-fly'', (while making use of the template), as follows:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|<nowiki>{{dropthing|backgroundT=mistyrose|class=collapsible selected| alignT=center|width=200px| Press to View|[[image:Hawthorn blossom.jpg|400px|thumb|center|''Hawthorn in bloom''.]] }}</nowiki>}}
The box produced in this way is just: 
{{dropthing|backgroundT=mistyrose|class=collapsible selected|alignT=center|width=200px| Press to View|[[image:Hawthorn blossom.jpg|400px|thumb|center|''Hawthorn in bloom''.]] }}
The template, for this box only, will be displayed in its open state, since the class ''selected'' has been added as an option.  Notice that the intended classes ''all'' need to be declared, and that the quotes were not needed. This entry entirely replaces the default class declaration.  Similarly, other classes could be used, though the set of classes available for the automatic formatting of tables could do with some extension.
====More Style Options====
To modify the template to add user-written style expressions, the template's existing style expression in the table line would be replaced as follows:
{{block|ff='Courier New', Courier, monospace|fs=1.1em|ta=left|<nowiki>style="{{{mystyleT|border:{{{border|1px solid black}}}; width:{{{width|300px}}}; background:{{{backgroundT|transparent}}} }}}"</nowiki> }}
Notice that the entire CSS style expression, (but not the attributes that followed it)), are now the default value of the ''mystyleT option''.  When this option is used in a template call the quotes for the value expression should not be used.
The typical template call, introducing new properties might then become: 
{{block|ff='Courier New', Courier, monospace|fs=1.1em|ta=left|<nowiki>{{dropthing|myclass=collapsible| alignT=center|mystyleT=border:3px solid brown; width:300px; background:mistyrose;color:darkgreen; font-weight:bold|Press to View|[[image:Hawthorn blossom.jpg|400px|thumb|center|''Hawthorn in bloom''.]] }}</nowiki>}}
and the result of making this template call is just:
{{dropthing|myclass=collapsible|alignT=center|mystyleT=border:3px solid brown; width:300px; background:mistyrose;color:darkgreen; font-weight:bold;|Press to View|[[image:Hawthorn blossom.jpg|thumb|400px|center|''Hawthorn in bloom''.]]<br>Other text could go here... }}
{{-}}
Notice that the intended new style statement must be rewritten in its entirety, and that now a  new CSS property (color of text), not included in the original design, has been added within the option statement.
If the mystyleT option were not used, the individual options could still be used.  If ''both'' the expression and the individual values are changed, it would be as well to study the possibility that one will override the other.
The template [[Template:Dropimage|'''Dropimage''']] has been modified to include user modification of class and style.
===Endpiece===
The three example types given in the above sections will hopefully introduce the reader to the making of templates.  Bear in mind that there are many aspects of templates not discussed here; for example, the notions of conditional behavior, loops, and defaults that themselves run as templates. Further reading about templates can be found in the links below.
Above all, learn how to use CSS styles in making your templates, and experiment with their effects.
==See Also==
*[[WB:SB|Sandbox]]: The Wikibooks editing and test window
*[[Help:Templates]]: Wikibooks main templates article 
*[[../Tables|Making Tables]]:  Wikitext methods for tables
*[[Help:Tables]]: Wikibooks main tables article
*[http://en.wikibooks.org/w/index.php?title=Special:AllPages&namespace=10 All Templates Namespace]  : Wikibooks templates alphabetical list
*[[:Category:Templates|Templates Category]]: Wikibooks templates listed by category
*[[CSS Programming]]: Helpful for CSS context 
*[http://www.w3schools.com/css/css_reference.asp CSS Reference List]: An external CSS Properties Reference
*[[w:Web_colors|Web Colors]]: A Wikipedia article on web colors
*[[Template:Dropimage]]: A multi-optioned drop-box template
*[[Template:Thetop]]: The most useful of the top section templates, for ''filling the space''.
*[[Template:Lorem ipsum]]: Test paragraph template
*[[../Class_and_Style_Notes|Class and Style Notes]]: About Wikitext classes and styles, as opposed to style sheets
*[[w:Wikipedia:Anatomy_of_a_template|Anatomy of a Template]]:  Wikipedia text with notes on templates as defaults, and conditionals.
</div>
</div>
===Nesting templates===
Templates may contain other templates&nbsp;— this is usually called "nesting". As the template is processed, the wikitext produced by any nested templates is transcluded into the nesting template, so that the final product is essentially processed from the most deeply nested template out. While fairly straightforward in application, it involves some noteworthy quirks and tricks.
To pass a parameter value to a nested template, place a parameter tag as the value of one of the nested template's parameters.
* Examples:
** Template:A contains <nowiki>"the quick brown {{B|{{{3}}}}} jumps over..."</nowiki>. This takes the value passed to the third positional parameter of Template:A and passes it as the first positional parameter of Template:B, then returns the wikitext produced by B as part of the phrase.
** Template:A contains <nowiki>"the quick brown {{B|waldo={{{3}}}}} jumps over..."</nowiki>. As above, except the third positional parameter of Template:A is passed to the named parameter "waldo" of Template:B.
Template parameters themselves can be chosen conditionally.
* Example:
** Template:A contains <nowiki>"the quick brown {{B|{{{3}}}=fox}} jumps over..."</nowiki>. Template:A passes the word "fox" to a parameter of Template:B that's named in A's third positional parameter.
A template can call itself, but will stop after one iteration to prevent an infinite loop.
When a nested template contains unmatched braces&nbsp;— as in {{tl|lb}}&#125;&nbsp;— the unmatched braces are treated as text during processing, and do not affect the parsing of braces in the nesting template. If the nested template is substituted, however, the substitution is processed first, and this ''will'' change how braces are parsed in the nesting template. This has little practical use, but can occasionally introduce unexpected errors.








[[Category:Template documentation]]
[[Category:Help templates]]
[[Category:BoyWiki]]

Latest revision as of 12:20, 13 April 2015


A list of BoyWiki templates can be found on Portal:Template index.

Any page whose name begins with "Template:", such as "Template:Documentation", can be used as a template. The content of a template can be added to a page by typing {{templatename}} while editing the page. When the page is later viewed, {{templatename}} is replaced by the content of the page "Template:templatename". If the page "Template:templatename" is later altered, all the pages with {{templatename}} in them will change automatically.

Amongst other things, templates are used to add recurring messages to pages in a consistent way, to add boilerplate such as template {{stub}} which indicates that the article is a fledgling.

When a template is automatically expanded and appears on a page, it is said to be "transcluded".

Templates are documented (or should be) at their pages. See Help:Template Documentation


General

Most templates are listed on Portal:Template index

Templates can contain any desired Wikitext, including calls to other templates. They have some limited programming capacities: customizable values (called parameters), calculation and branchings (using parser functions), and access to wiki-specific variables (magic words), such as dates, times, and page names. They may also contain tags which define which parts of the wikitext are to be included when the template is transcluded or substituted. This means that the appearance of the template page itself need not be the same as that of the transcluded content (for example, it can contain documentation, categories, etc. for the template).

How to do it: To transclude a template to an article or page, type {{template name}} in the wikitext at the place where the template is to appear. The prefix "Template:" need not be included, and an initial capital is not necessary.

Note: Attempting to transclude a template that does not exist produces a red link, just like linking to any other nonexistent page. Following the link allows one to create that particular template.

Also see: Help:Templates for beginners

  • TEMPLATES are just blocks of saved text that have been given names. Some are ordinary text paragraphs and some contain wikitext to make headings, indents, tables, and the like. In a simple case, by typing a template's name in the work, an entire block of text is added to the page with all of its formats and other parts, just as if it had been typed by the user. This behavior can be repeated at any point that the user wants, and almost any work that is found on a wiki page could be placed within a template to do this. The main effort as you might suppose, lies in its initial design.
  • NAMES of templates are assigned when they are first saved. The name must be unique, and it is used when a template is called for use. Sometimes other text is also used along with the name; it can include any options and parameters.
  • OPTIONS allow the user to vary the template's usual behavior.. The usual behavior suits most situations but the designer builds-in ways of changing things just in case. Option values are usually limited to a short list so these are described in a template's documentation. For example, option values for an option called align might include only left, right, or center, and no others. Templates do not always need options, since their default behavior is often enough.
  • DEFAULTS are the values used by a template when the user did not say. Default values are specified in design, and they could apply to formats or to user text inputs. For example, in the alignment example above, if the align option was not used, the template could use left, provided that left had been specified in design as its default. In the same way if the user forgets to type a text input, the template could use a pre-planned default input instead of the missing parameter; sometimes just a code to say something was forgotten.
  • PARAMETERS are usually bits of text that a user enters for a template to process. For example, if a template makes text red, it still needs to know the text to color; this text is called a parameter, and the text is included by the user when the template is called for use. Sometimes parameters contain text like code to insert an image, or even a gallery or a table; it just depends what the template is designed for. A template can even be the parameter of another template; for example, a template to insert a test paragraph might occupy the parameter space of a template to make a text box. The new paragraph would then appear in a new text box.
  • MORE GENERALLY, templates let us do much of the preparation in advance of making a page, and let us insert a block of typing, be it code to make tables, boxes, and other structures, or just a paragraph of text that is used a lot.

Usage syntax

Parameters

The basic transclusion syntax given above can be extended by the addition of parameters, which are used to control the template's output. The syntax for this is

  • {{template name|parameter|parameter|...}}

where each "parameter" may either contain just a value (these are called unnamed parameters) or be of the form name=value (named parameters). The first, second, etc. unnamed parameters are equivalent to parameters named "1", "2", etc.

Whitespace characters (spaces, tabs, returns) are stripped from the beginnings and ends of named parameter names and values, but not from the middle: thus {{ ... | myparam = this is a test }} has the same effect as {{ ... |myparam=this is a test}}. This does not apply to unnamed parameters, where the whitespace characters are preserved.

What parameters (if any) can or should be passed to a template, and how they are to be named, depends on the coding of that template. Named parameters can be defined in any order. Superfluous or misnamed parameters will be ignored; undefined parameters will be assigned default values. If a parameter is defined more than once, the last value takes effect.

The value of a parameter can be the empty string (pipe or equals sign followed immediately by the next pipe or the closing braces). This is different from leaving the parameter undefined (although templates are often coded so as to behave the same in both cases).


Other details

Template names are exactly like other page names case-sensitive except for the first letter, with spaces indistinguishable from underscores. If the symbol # (normally used to link to a section of a page) appears in a transclusion, then it and any characters that follow it are ignored.

Notice that the same double-brace syntax is used for many MediaWiki variables and parser functions (see Help:Magic words). For example, the code {{NAMESPACE}} may look like a template call, but it is actually a variable whose value is the namespace prefix of the current page.


Creating and editing templates

Templates are created and edited in much the same way as any other page: choose an appropriate name, navigate to that page, then click the Edit tab or create a new page as needed. Templates intended for your own personal use or for experimentation can be created in your own user space. Anything that can be included on a normal page or article can be included on a template, including other templates (called subtemplates). Templates often make use of programming features — parameters, parser functions and other magic words — which allow the transcluded content to vary depending on context. There are also special tags to control which information is transcluded and which is not.

Before creating a template, do a quick search for existing templates (e.g. by exploring Portal:Template index) to see if there's already a template that does what you want, or a similar template whose code can be copied and modified (or left in place and expanded). Look for generic templates on which the new template can be based (for example, navbox templates can be easily created by calling the generic Template:Navbox).

There is no hard rule about what name to choose for a template — make it short but reasonably descriptive. If similar templates exist, try to follow a consistent naming pattern. Templates can be renamed without breaking existing transclusions, provided a redirect to the new template name is left behind.

Be extremely careful when editing existing templates — changes made can affect a large number of pages, often in ways you might not expect.



System variables and conditional logic

Template code often makes use of the variables and parser functions described at Help:Magic words, in order to make the template's behaviour depend on the environment (such as the current time or namespace) or on the parameter values which are passed to it. They can also be used for arithmetical calculations. Notice that full string manipulation is not available (although templates have been created which provide such functionality, though very inefficiently and imperfectly), nor are certain standard programming features such as loops and variable assignment.

Some of the most often used variables and functions are listed hereafter. For more, see Help:Magic words.

Examples of core parser functions
Description Text entered Result
Uppercasing text {{uc: Heavens to BETSY! }} HEAVENS TO BETSY!
Lowercasing text {{lc: Heavens to BETSY! }} heavens to betsy!
Getting a namespace name {{NS: 1 }} Talk
Getting a Wikipedia URL {{fullurl: pagename }} https://www.boywiki.org/en/Pagename

The ParserFunctions extension gives more programming-oriented parser functions.

Examples of extension parser functions
Description Text Entered Result
Testing between options {{#ifeq: yes | yes | Hooray...! | Darn...! }}
{{#ifeq: yes | no | Hooray...! | Darn...! }}
Hooray...!
Darn...!
Testing if a parameter is set {{#if: {{{param|}}} | Hooray...! | Darn...! }} Darn...!
Making a calculation (mathematics)
[area of circle of radius 4, to 3 decimal places]
{{#expr: ( pi * 4 ^ 2 ) round 3 }} 50.265
Testing the result of a calculation
[is 1230 even or odd?]
{{#ifexpr: 1.23E+3 mod 2 | Odd | Even }} Even
Examples of System Variables
Description Text Entered Result (for this help page)
Page names {{PAGENAME}}
{{FULLPAGENAME}}
Templates
Help:Templates
Name of the current namespace {{NAMESPACE}} Help
Number of registered users {{NUMBEROFUSERS}} 225
Number of pages in a given category {{PAGESINCATEGORY:"Weird Al" Yankovic albums}} 0
Current software version {{CURRENTVERSION}} 1.42.1
Timestamp of last revision {{REVISIONTIMESTAMP}} 20150413122054

Text Paragraphs

The code for a template need not start with any special character or symbol. The main consideration is that the code performs the required action, just as if it were typed directly onto the page. At the 'end of the code block, be sure to add the <noinclude></noinclude> tags as mentioned above.

All of the existing Wikitext and HTML code that can be used in a page can be used for a text template. The user of a page does not have access to the parts associated with styles, namely the heading of the web page and their style sheets. As a result, users are limited to modifying the parts of the page that are available, the text within the body of the page. Those familiar with web page design will know that the only remaining available method is to modify the page's text with in-line styles. Working methods use the <div></div> tags and the <span></span> tags, thanks to a feature of Wikitext that allows the use of HTML coding within it. CSS, (Cascading Style Sheet), properties and values are used within these tags to modify the text styles that would otherwise apply.


The Simplest Case

Before doing any formatting, consider the method for making a template from a simple block of text. Type a block of text, with all of its formats and page layout in place, then save the block as a template. It is as simple as that.


Making Boxes


The following sections make box or table templates from Wikitext. They can also be made with HTML tables in the same way. When it comes to making such a template, wikitext is fine but when a table is needed to go into a template as its parameter, or part of its parameter, an HTML table should be used instead.

This WikiBooks text touches on HTML table structures, and explains how to use styles.


The Box Structure

Boxes are essentially tables, in fact table cells. The CSS property list to format tables is extensive. Simple boxes make use of the table container, and one or two cells within it.

Apart from the table container, the other structures of a table include its rows, and cells. In the case below there are two rows, each with only one cell in them. Each part of a table has properties that affect it, and an example of typical table coding can be seen in the listing below.

Parameters and Options

It is intended to provide three options along with the two parameters. The options are to be background,width, and align. The parameter names are to be 1 and 2, with the labels heading and content.

Nesting templates

Templates may contain other templates — this is usually called "nesting". As the template is processed, the wikitext produced by any nested templates is transcluded into the nesting template, so that the final product is essentially processed from the most deeply nested template out. While fairly straightforward in application, it involves some noteworthy quirks and tricks.

Examples

Here are two examples of box templates that are easy to use and are useful to those just starting out.


{{Box1 start}}
Sample text
{{Boxes end}}
gives...

Sample text

{{Box1 start}}
Box1 text
{{Box2 start}}
Box2 text
{{Boxes end}}
gives...

First box text

Second box text

Making a Basic Wiki Table

{|class="wikitable"
! one box
|} 
gives...
one box
{|class="wikitable"
! 
!Top row
|-
!First row
| (add some txt)
|}
gives...
Top row
First row (add some txt)
{| class="wikitable"
!top row
!This is text
!This is more txt
!This is more txt
|-
!line1
|(add some txt)
|(add some txt)
|(add some txt)
|-
!line2
|(add some txt)
|(add some txt)
|(add some txt)
|-
!line3
|(add some txt)
|(add some txt)
|(add some txt)
|}
gives...
top row This is text This is more txt This is more txt
line1 (add some txt) (add some txt) (add some txt)
line2 (add some txt) (add some txt) (add some txt)
line3 (add some txt) (add some txt) (add some txt)
{| class="wikitable" style="float: right;: 1em auto 1em auto;"
|+ '''(this is my table name)'''
! scope="col" | top row
! scope="col" | This is text
! scope="col" | This is text
|-
| row 1  || (add some txt) || (add some txt)
|-
| row 2 || (add some txt) || (add some txt)
|}
gives...
(this is my table name)
top row This is text This is text
row 1 (add some txt) (add some txt)
row 2 (add some txt) (add some txt)


If you float the wikitable right, you can make your text rap around the box without leaving large blank spaces on your page. This is often very useful.

(This is how a line would look.)


External Links