User:Darkfire/Sandbox/Sandbox Beta

From Avlis Wiki
Revision as of 19:15, 27 November 2022 by Darkfire (talk | contribs) (Just trying to figure out how to do this don't mind me)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This is a user sandbox of Darkfire. A user sandbox is a subpage of the user's user page. It serves as a testing spot and page development space for the user, and is not an Avlis wiki article.


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). -- Darkfire --


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.


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 through sec25.


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
  • 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 with This 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)