Difference between revisions of "Template:See Also2"

From Pathfinder Wiki
Line 9: Line 9:
 
==Example==
 
==Example==
 
<div class="toccolours">
 
<div class="toccolours">
:<nowiki>{{</nowiki>See Also2|honorname=Tumbling & Balancing}}
+
:<nowiki>{{</nowiki>See Also|honorname=Camping Skills IV}} &rarr;{{See Also|honorname=Camping Skills IV}}
 +
:<nowiki>{{</nowiki>See Also|honorname=Basic Water Safety}} &rarr;{{See Also|honorname=Basic Water Safety}}
 +
:<nowiki>{{</nowiki>See Also|honorname=Tumbling & Balancing}} &rarr;{{See Also|honorname=Tumbling & Balancing}}
 +
 
 
</div>
 
</div>
  
{{See Also2|honorname=Tumbling & Balancing}}
 
  
 
==Mechanics==
 
==Mechanics==
Line 21: Line 23:
 
Then define an IA category.  This honor is related to the IA pages in the category AY_Honors/Prerequisite_IA/''honorname''/language.
 
Then define an IA category.  This honor is related to the IA pages in the category AY_Honors/Prerequisite_IA/''honorname''/language.
  
The markup then adds together the number of pages in these two categories, and if it's greater than 0, invokes some dpl to show the pages. There are two dpl sections because we are extracting honor names and IA page names from two different templates (honor_landing and IA_desc).
+
If honcat has any pages in it, we create a variable dplList, which is the output of a dpl query.
 +
We then enter a loop, converting the list of dpl hist into dplItems, formatted into a link with the translated honorname as the link display.
 +
 
 +
This is repeated for iacat.
  
 
Of special note is that the dpl is using categorymatch instead of category.  The reason for this is because category can specify multiple categories using the "&" character as a delimiter, and some honornames (I'm looking at you Tumbling & Balancing) have & in them.  This has tragic consequences for dpl's category specifier.  The categorymatch specifier is very much like category, except that it can use % as a wildcard - using the same format as an SQL LIKE statement.  If there are no % wildcards, then it's largely the same as category, except that categorymatch does not recognize & as a delimiter.
 
Of special note is that the dpl is using categorymatch instead of category.  The reason for this is because category can specify multiple categories using the "&" character as a delimiter, and some honornames (I'm looking at you Tumbling & Balancing) have & in them.  This has tragic consequences for dpl's category specifier.  The categorymatch specifier is very much like category, except that it can use % as a wildcard - using the same format as an SQL LIKE statement.  If there are no % wildcards, then it's largely the same as category, except that categorymatch does not recognize & as a delimiter.
Line 27: Line 32:
 
That bug took half a week to track down and slay.
 
That bug took half a week to track down and slay.
  
</noinclude><includeonly>{{#vardefine:honorname|{{{honorname|{{#titleparts:{{PAGENAME}}|1|2}}}}}}}{{#vardefine:honcat|AY Honors/Prerequisite Answer/{{#var:honorname}}{{GetLangSuffix}}}}{{#vardefine:iacat|AY Honors/Prerequisite IA/{{#var:honorname}}{{GetLangSuffix}}}}{{#ifexpr:{{PAGESINCATEGORY:{{#var:honcat}}}}+{{PAGESINCATEGORY:{{#var:iacat}}}} > 0|{{#dpl:
+
</noinclude><includeonly>{{#vardefine:honorname|{{{honorname|{{#titleparts:{{PAGENAME}}|1|2}} }}} }}{{#vardefine:honcat|AY Honors/See Also/{{#var:honorname}}{{GetLangSuffix}}}}{{#vardefine:iacat|AY Honors/Prerequisite IA/{{#var:honorname}}{{GetLangSuffix}}}}{{#vardefine:honcatsize|{{PAGESINCATEGORY:{{#var:honcat}}}}}}{{#if:{{#var:honcatsize}}
|include={honor_landing}:honorname
+
    |{{#vardefine:dplList
|format=,[[{{#titleparts:%PAGE%|2|1}}¦,]]%{{!}}%
+
                  |{{#dpl:format=,%PAGE%,%{{!}}%
|categorymatch={{#var:honcat}}
+
                        |categorymatch={{#replace:{{#var:honcat}}|&|%}}
|notcategory=AY Honors/Secondary
+
                        |notcategory=AY Honors/Secondary
|nottitleregexp=.*/en$
+
                        |nottitleregexp=.*/en$
|order=ascending
+
                        |order=ascending
|suppresserrors = true
+
                        |debug=0
}}{{#dpl:
+
                  }}
|include={IA desc{{GetLangSuffix}}}:pagename
+
      }}{{#loop:index
|format=,[[%PAGE%¦,]]%{{!}}%
+
              |0
|categorymatch={{#var:iacat}}
+
              |{{#var:honcatsize}}
|nottitleregexp=.*/en$
+
              |{{#vardefine:dplItem|{{#explode:{{#var:dplList}}|%{{!}}%|{{#var:index}}}}}}
|order=ascending
+
                {{#if:{{#var:dplItem}}
|suppresserrors = true
+
                    |[[{{#titleparts:{{#var:dplItem}}|2}}{{!}}{{GetHonorName|page={{#var:dplItem}}}}]]%{{!}}%}}}}}}{{#vardefine:iacatsize|{{PAGESINCATEGORY:{{#var:iacat}}}}}}{{#if:{{#var:iacatsize}}
}}}}</includeonly>
+
    |{{#vardefine:dplList
 +
                  |{{#dpl:format=,%PAGE%,%{{!}}%
 +
                        |categorymatch={{#replace:{{#var:iacat}}|&|%}}
 +
                        |notcategory=AY Honors/Secondary
 +
                        |nottitleregexp=.*/en$
 +
                        |order=ascending
 +
                        |debug=0
 +
                  }}
 +
      }}{{#loop:index
 +
              |0
 +
              |{{#var:iacatsize}}
 +
              |{{#vardefine:dplItem|{{#explode:{{#var:dplList}}|%{{!}}%|{{#var:index}}}}}}
 +
                {{#if:{{#var:dplItem}}
 +
                    |[[{{#titleparts:{{#var:dplItem}}|2}}{{!}}{{GetHonorName|page={{#var:dplItem}}}}]]%{{!}}%}}}}}}{{#if:{{{debug|}}}
 +
|<li>dplList={{#var:dplList}}</li>
 +
<li>honcat={{#var:honcat}}</li>
 +
}}</includeonly>

Revision as of 03:38, 18 May 2021

Displays a list of all the honors tagged as a "See Also" for which the specified honor. This includes all pages for which it is listed as a prerequisite, as well as any that are adjacent in a series labelled with Roman numerals. Every Honor-Link is separated by "%|%".

Parameters

honorname
This parameter specifies the name of the honor. If omitted, the template assumes the can be found as the second element of the page title invoking the template.

This template is related to Template:Honor prerequisite which is used as the answer to most requirements to earn some other honor. That template will add whatever invokes it to [[Category:AY Honors/See Also/honor]], where honor is the prerequisite. Every honor in that category has honor as a prerequisite or is related to honor in some other way (such as being the adjacent in a series. This template merely lists all the honors in that category to indicate that once you've earned this one, you're partway to earning another.

Example

{{See Also|honorname=Camping Skills IV}} →Camp Safety - Advanced%|%Outdoor Leadership%|%Camping Skills III%|%
{{See Also|honorname=Basic Water Safety}} →Swimming - Beginner%|%
{{See Also|honorname=Tumbling & Balancing}} →Tumbling & Balancing - Advanced%|%


Mechanics

First define a variable for honorname. If the honorname parameter is specified, it gets used. Otherwise, it extracts the honorname from the second element of the page title.

Next define the honor category honcat. We're looking for the category AY_Honors/See_Also/honorname/language. The honor specified by honorname is related to every honor in this category, such as if it is a prerequisite, or if it is adjacent in a series.

Then define an IA category. This honor is related to the IA pages in the category AY_Honors/Prerequisite_IA/honorname/language.

If honcat has any pages in it, we create a variable dplList, which is the output of a dpl query. We then enter a loop, converting the list of dpl hist into dplItems, formatted into a link with the translated honorname as the link display.

This is repeated for iacat.

Of special note is that the dpl is using categorymatch instead of category. The reason for this is because category can specify multiple categories using the "&" character as a delimiter, and some honornames (I'm looking at you Tumbling & Balancing) have & in them. This has tragic consequences for dpl's category specifier. The categorymatch specifier is very much like category, except that it can use % as a wildcard - using the same format as an SQL LIKE statement. If there are no % wildcards, then it's largely the same as category, except that categorymatch does not recognize & as a delimiter.

That bug took half a week to track down and slay.