User:Stux/getCurrPage-lookup Template

From Homestar Runner Wiki

< User:Stux(Difference between revisions)
Jump to: navigation, search
(and why no code? because I haven't figured out the parameter spec yet ^_^;;)
(rm cat)
 
(includes 6 intermediate revisions)
Line 1: Line 1:
-
<noinclude>
+
{{<!--
 +
-->{{{1}}}<!-- /* call a template based on 1st parameter, we want to get a value by index */
 +
-->|{{#expr: <!-- /* we want to add an offset to the returned index */
 +
  -->{{<!--
 +
  -->{{{1}}}<!-- /* call the template again to get its index by name */
 +
  -->|{{#if:{{{name|}}}|{{{name|}}}|{{PAGENAME}}}}<!-- /* by default, if a name isn't specified, use {{PAGENAME}}. */
 +
  -->|n=1}}<!-- /* end 2nd call */
 +
-->+{{#if:{{{next|}}}|1|{{#if:{{{prev|}}}|-1|0}}}}<!-- /* calculate offset
 +
-->}}<!-- /* end #expr: */
 +
-->}}<!-- /* end first call */ --><noinclude>
This crazy meta-template will query another template for its nav index or name based on the current <code><nowiki>{{PAGENAME}}</nowiki></code> value.  Optionally, it can also provide the next and previous name/index values based on the same criteria.
This crazy meta-template will query another template for its nav index or name based on the current <code><nowiki>{{PAGENAME}}</nowiki></code> value.  Optionally, it can also provide the next and previous name/index values based on the same criteria.
Line 5: Line 14:
=== Usage ===
=== Usage ===
:<code><nowiki>{{getCurrPage-lookup|</nowiki>''template-name''|[name=''</code>alternative name<code>'']|[prev=1]|[next=1]}}</code>
:<code><nowiki>{{getCurrPage-lookup|</nowiki>''template-name''|[name=''</code>alternative name<code>'']|[prev=1]|[next=1]}}</code>
 +
 +
*''template-name'' {{--}} the template to use to query the name and index
 +
*''name'' {{--}} (optional) the name to use for lookup, otherwise use <code><nowiki>{{PAGENAME}}</nowiki></code>
 +
*''prev'' {{--}} if set, return the previous item in the nav list
 +
*''next'' {{--}} if set, return the next item in the nav list
 +
 +
'''Note:''' if both ''prev'' and ''next'' are set, only ''next'' is obeyed.  If neither are set, the template returns the lookup value for the current name.  In most cases this will be the value of <code><nowiki>{{PAGENAME}}</nowiki></code> itself (and so using <code><nowiki>{{PAGENAME}}</nowiki></code> directly would be more efficient!)
=== Expected Input Template Parameter Format ===
=== Expected Input Template Parameter Format ===
Line 21: Line 37:
Would return a nav index value based on a Page Name.
Would return a nav index value based on a Page Name.
-
[[Category:QuickNav Assistance Templates|{{PAGENAME}}]]
+
=== Example ===
 +
*For reference, see how {{t|acharnav}} uses this template to call {{t|charnav-lookup}} dynamically
 +
 
 +
<!--[[Category:QuickNav Assistance Templates|{{PAGENAME}}]]-->
</noinclude>
</noinclude>

Current revision as of 03:46, 30 January 2021

{{{{{1}}}|Expression error: Unrecognised punctuation character "{"}}

This crazy meta-template will query another template for its nav index or name based on the current {{PAGENAME}} value. Optionally, it can also provide the next and previous name/index values based on the same criteria.

[edit] Usage

{{getCurrPage-lookup|template-name|[name=alternative name]|[prev=1]|[next=1]}}
  • template-name — the template to use to query the name and index
  • name — (optional) the name to use for lookup, otherwise use {{PAGENAME}}
  • prev — if set, return the previous item in the nav list
  • next — if set, return the next item in the nav list

Note: if both prev and next are set, only next is obeyed. If neither are set, the template returns the lookup value for the current name. In most cases this will be the value of {{PAGENAME}} itself (and so using {{PAGENAME}} directly would be more efficient!)

[edit] Expected Input Template Parameter Format

We expect the template to take the following parameters:

{{template-name|idx or name (to lookup)|[n=1]}}

The optional n=1 parameter determines whether the lookup is by index or by name:

{{template-name|idx}}

This returns a full (or sometimes partial) page name value based on its nav index. Also,

{{template-name|name|n=1}}

Would return a nav index value based on a Page Name.

[edit] Example


Personal tools