User:Gorgon/Sandbox/Sandbox Beta: Difference between revisions
m (New template to test for transcluding sections.) |
m (Added "Technical details" section for information about using pipes "|" (or wikitables containing them) as template parameters.) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{#switch:{{{2}}} | <noinclude>{{<!-- sec -->User:Gorgon/Sandbox/Sandbox_Beta | User:Gorgon/Sandbox | 1 }} | ||
</noinclude>{{#switch:{{{2}}} | |||
|1={{{{{ns|}}}:{{{1}}} | |1={{{{{ns|}}}:{{{1}}} | ||
|sec2=|sec3=|sec4=|sec5=|sec6=|sec7=|sec8=|sec9=|sec10= | |sec2=|sec3=|sec4=|sec5=|sec6=|sec7=|sec8=|sec9=|sec10= | ||
Line 128: | Line 129: | ||
<pre style="white-space: pre-wrap"> | <pre style="white-space: pre-wrap"> | ||
This is a sample article, with a few sections | This is a sample article, with a few sections | ||
<onlyinclude><nowiki>{{{sec1|This is the first section}}}</nowiki></onlyinclude> | <onlyinclude><nowiki>{{{sec1 |This is the first section}}}</nowiki></onlyinclude> | ||
<onlyinclude><nowiki>{{{sec2|This is the second section}}}</nowiki></onlyinclude> | <onlyinclude><nowiki>{{{sec2 |This is the second section}}}</nowiki></onlyinclude> | ||
</pre> | </pre> | ||
Line 140: | Line 141: | ||
'''Usage: ''' <code><nowiki>{{sec|PAGENAME|SECTIONNUMBER}}</nowiki></code> | '''Usage: ''' <code><nowiki>{{sec | PAGENAME | SECTIONNUMBER }}</nowiki></code> | ||
Line 151: | Line 152: | ||
To transclude the <code>sec1</code> section from the <code>Test_Article</code> example above, use: | To transclude the <code>sec1</code> section from the <code>Test_Article</code> example above, use: | ||
<code><nowiki> | <code><nowiki>{{sec | Test_Article | 1 }}</nowiki></code> | ||
To transclude the <code>sec2</code> section from the <code>Test_Article</code> example above, use: | To transclude the <code>sec2</code> section from the <code>Test_Article</code> example above, use: | ||
<code><nowiki>{{{sec|Test_Article|2}}</nowiki></code> | <code><nowiki>{{sec | Test_Article | 2 }}</nowiki></code> | ||
==== Other Usage ==== | |||
The author gave a few other examples in his [http://en.wikisource.org/wiki/User:Sanbeg/Test test page], using an extra <code>ns =</code> parameter after the SECTIONNUMBER, to modify which namespace the PAGENAME belongs to, so it doesn't need to be included. | |||
An example of the previous <code>User:John/Test_Article</code> PAGENAME done this way would be: | |||
<code><nowiki>{{sec | John/Test_Article | 1 | ns = User }}</nowiki></code> | |||
* In this case there isn't much improvement (more confusing even), since the username still needs to be included, but it may be useful for the Template namespace, or others. | |||
One other example he gave didn't use this template. Only the markup in the source article page, and transclusion with extra parameters. | |||
Still using the '''Test_Article''' in the example above as a source, with the example code: | |||
<code><nowiki>{{Test_Article | sec1 = }}</nowiki></code> | |||
This transcludes everything except section 1 ('''sec1'''), since the contents of that section are unset by the empty parameter value given. | |||
'''Result: ''' <code>This is the second section</code> | |||
* This is basically the inverse of how this template works, since the template transcludes all sections, then empties the values of all that aren't selected. With the transclusion method above, everything is transcluded, and you specify individual sections that you don't want to include (or replacements for them - read on). | |||
This also can be used to replace individual sections of the whole transcluded article page, by supplying a new value for each parameter. | |||
E.g., <code><nowiki>{{Test_Article | sec1 = Hello World! }}</nowiki></code> adds <code>Hello World!</code> before also transcluding <code>This is the second section</code>. | |||
With source article pages that have many sections set up this way, several can be left out or replaced. If '''Test_Article_2''' has 3 or more sections marked the same as the original '''Test_Article''', this can be demonstrated with the following example: | |||
<code><nowiki>{{Test_Article_2 | sec1 = Hello World! | sec3 = }}</nowiki></code> | |||
* This would add <code>Hello World!</code> instead of section 1, transclude section 2 normally with <code>This is the second section</code>, skip transcluding section 3, and then transclude whatever other sections come after that normally. | |||
=== Technical details === | |||
If you intend to use <span class="plainlinks">[http://www.mediawiki.org/wiki/Help:Tables wikitables]</span> as parameter values in this template, then you need to know this: | |||
<span class="plainlinks">[http://www.mediawiki.org/wiki/Help:Templates Templates]</span> have a problem handling parameter data that contains pipes "<code>|</code>", unless the pipe is inside another template <code><nowiki>{{name | param1 }}</nowiki></code>, or inside a piped link <code><nowiki>[[Help:Template | help]]</nowiki></code>. Therefore templates can not handle wikitables as input, unless you escape them by using the '''<nowiki>{{!}}</nowiki>''' magic word (parser function - see: <span class="plainlinks">[http://www.mediawiki.org/wiki/Help:Magic_words#Other Help:Magic words#Other]</span>). This makes it hard to use wikitables as parameters in templates. Instead, the usual solution is to use [[Wikipedia:Help:Table#Other_table_syntax | HTML wikimarkup]] for the table code, which is more robust. | |||
'''''Note:''' [[Template:!]] functionality was replaced in MediaWiki version 1.24 by the '''<nowiki>{{!}}</nowiki>''' magic word, and the template is ignored when using it.'' | |||
=== Copy of Original Documentation ([http://en.wikisource.org/wiki/User:Sanbeg/Sec Steve Sanbeg's Userspace on Wikisource]) === | === Copy of Original Documentation ([http://en.wikisource.org/wiki/User:Sanbeg/Sec Steve Sanbeg's Userspace on Wikisource]) === | ||
* This was also in the Template namespace before he finalized [http://www.mediawiki.org/wiki/Extension:Labeled_Section_Transclusion Extension:Labeled Section Transclusion], and the template name was recycled. It can still be viewed in its [http://en.wikisource.org/w/index.php?title=Template:Sec&oldid=4659477 last revision] before being recycled as a redirect. | |||
* [http://wikisource.org Wikisource] and [http://www.mediawiki.org Mediawiki] links have been reformatted to work here (and a few typo fixes). | * [http://wikisource.org Wikisource] and [http://www.mediawiki.org Mediawiki] links have been reformatted to work here (and a few typo fixes). | ||
Line 187: | Line 234: | ||
</div> | </div> | ||
{{ns detect | template = [[Category:Templates |{{PAGENAME}}]] }}</noinclude> | |||
</noinclude> |
Latest revision as of 06:51, 3 February 2017
Template:Sec (Section Transclusion) Documentation
Credit
As with most general purpose templates people think of creating, someone usually thought of the same idea before, and this template is another example of that (saved me the trouble of making a crappier version of it myself). -- Gorgon --
The original test version of this template was created in Steve Sanbeg's userspace on Wikisource.
- Steve Sanbeg is also the author of Extension:Labeled Section Transclusion, which will hopefully replace this here one day (see the Description below).
- While the documentation and format of this template have been changed, the original code should be essentially the same.
Description
This template is for transcluding pre-marked sections of articles.
- Extension:Labeled Section Transclusion is an improved method of doing this task, and this template should be considered deprecated if that extension is implemented here.
- While Wikipedia's Selective transclusion without using the labeled section method does work here, it is very limited/restricted, and this template allows more flexibility and ease of use.
Usage and Examples
Step 1
Add section tags to the article page that you want to transclude the information from, as shown below:
This is a sample article, with a few sections <onlyinclude>{{{sec1 |This is the first section}}}</onlyinclude> <onlyinclude>{{{sec2 |This is the second section}}}</onlyinclude>
- This is the article titled Test_Article used in Step 2 below.
- This template has a limit of 25 numbered sections, so you can only use
sec1
throughsec25
.
Step 2
Add the following code to the target article page that you want to transclude the previously defined section(s) of Test_Article to:
Usage: {{sec | PAGENAME | SECTIONNUMBER }}
- Replace PAGENAME with the source article page name (Test_Article in the example above). E.g.,
Test_Article
- If the source article page is outside of the Main namespace, include the namespace (and full path from it). E.g.,
User:John/Test_Article
- If the source article page is outside of the Main namespace, include the namespace (and full path from it). E.g.,
- Replace SECTIONNUMBER with the matching section number that you want to transclude from the source article (do not include the sec prefix). E.g.,
1
-25
Examples
To transclude the sec1
section from the Test_Article
example above, use:
{{sec | Test_Article | 1 }}
To transclude the sec2
section from the Test_Article
example above, use:
{{sec | Test_Article | 2 }}
Other Usage
The author gave a few other examples in his test page, using an extra ns =
parameter after the SECTIONNUMBER, to modify which namespace the PAGENAME belongs to, so it doesn't need to be included.
An example of the previous User:John/Test_Article
PAGENAME done this way would be:
{{sec | John/Test_Article | 1 | ns = User }}
- In this case there isn't much improvement (more confusing even), since the username still needs to be included, but it may be useful for the Template namespace, or others.
One other example he gave didn't use this template. Only the markup in the source article page, and transclusion with extra parameters.
Still using the Test_Article in the example above as a source, with the example code:
{{Test_Article | sec1 = }}
This transcludes everything except section 1 (sec1), since the contents of that section are unset by the empty parameter value given.
Result: This is the second section
- This is basically the inverse of how this template works, since the template transcludes all sections, then empties the values of all that aren't selected. With the transclusion method above, everything is transcluded, and you specify individual sections that you don't want to include (or replacements for them - read on).
This also can be used to replace individual sections of the whole transcluded article page, by supplying a new value for each parameter.
E.g., {{Test_Article | sec1 = Hello World! }}
adds Hello World!
before also transcluding This is the second section
.
With source article pages that have many sections set up this way, several can be left out or replaced. If Test_Article_2 has 3 or more sections marked the same as the original Test_Article, this can be demonstrated with the following example:
{{Test_Article_2 | sec1 = Hello World! | sec3 = }}
- This would add
Hello World!
instead of section 1, transclude section 2 normally withThis is the second section
, skip transcluding section 3, and then transclude whatever other sections come after that normally.
Technical details
If you intend to use wikitables as parameter values in this template, then you need to know this:
Templates have a problem handling parameter data that contains pipes "|
", unless the pipe is inside another template {{name | param1 }}
, or inside a piped link [[Help:Template | help]]
. Therefore templates can not handle wikitables as input, unless you escape them by using the {{!}} magic word (parser function - see: Help:Magic words#Other). This makes it hard to use wikitables as parameters in templates. Instead, the usual solution is to use HTML wikimarkup for the table code, which is more robust.
Note: Template:! functionality was replaced in MediaWiki version 1.24 by the {{!}} magic word, and the template is ignored when using it.
Copy of Original Documentation (Steve Sanbeg's Userspace on Wikisource)
- This was also in the Template namespace before he finalized Extension:Labeled Section Transclusion, and the template name was recycled. It can still be viewed in its last revision before being recycled as a redirect.
- Wikisource and Mediawiki links have been reformatted to work here (and a few typo fixes).