Difference between revisions of "Template:List lookup helper"

From QBWiki
Jump to navigation Jump to search
m
m
Line 1: Line 1:
{{#ifeq:{{#var:page_name}}|{{{1}}}|<!--
+
<includeonly>{{#ifeq:{{#var:page_name}}|{{{1}}}|<!--
 
If page name is previously defined AND it equals arg1 then this invocation of the template can be skipped. This maintains the invariant of "loaded exactly once" if this is transcluded in another template that is itself transcluded multiple times.
 
If page name is previously defined AND it equals arg1 then this invocation of the template can be skipped. This maintains the invariant of "loaded exactly once" if this is transcluded in another template that is itself transcluded multiple times.
-->|{{#vardefine:page_name|{{{1}}}}}{{#vardefine:loaded_page|{{:{{#var:page_name}}}}}}{{#vardefine:minindex|0}}{{#vardefine:maxindex|1}}<!--
+
-->|{{Add|invocations|1}}{{#vardefine:page_name|{{{1}}}}}{{#vardefine:loaded_page|{{:{{#var:page_name}}}}}}{{#vardefine:minindex|0}}{{#vardefine:maxindex|1}}<!--
 
Find the upper bound of the size in steps of 2^n
 
Find the upper bound of the size in steps of 2^n
 
-->{{#while:
 
-->{{#while:
Line 16: Line 16:
 
{{#vardefine:index|{{#expr:floor(({{#var:maxindex}}+{{#var:minindex}})/2)}}}}
 
{{#vardefine:index|{{#expr:floor(({{#var:maxindex}}+{{#var:minindex}})/2)}}}}
 
}}{{Copy|index|length}}<!--
 
}}{{Copy|index|length}}<!--
-->{{#loop:ii|1|{{#var:length}}|{{#vardefine:entry_{{#var:ii}}|{{#explode:{{#var:loaded_page}}|*|{{#var:ii}}|1000}}}}}}}}<noinclude>
+
-->{{#loop:ii|1|{{#var:length}}|{{#vardefine:entry_{{#var:ii}}|{{#explode:{{#var:loaded_page}}|*|{{#var:ii}}|1000}}}}}}}}</includeonly><noinclude>
 
{{Template doc|
 
{{Template doc|
 
Given a list page, loads it exactly once and sets up enough variables it will not need to be loaded again to retrieve any entry. If this template has been invoked before with the same page_name, no-op.
 
Given a list page, loads it exactly once and sets up enough variables it will not need to be loaded again to retrieve any entry. If this template has been invoked before with the same page_name, no-op.
Line 23: Line 23:
 
* length - the length of the list
 
* length - the length of the list
 
* entry_i - the entry in the list at position ''i'', where i is in <nowiki>[1, length-1]</nowiki> (0-indexed)
 
* entry_i - the entry in the list at position ''i'', where i is in <nowiki>[1, length-1]</nowiki> (0-indexed)
 +
 +
There is also the housekeeping variable "invocations", which equals the number of times this template was resolved.
  
 
<pre>
 
<pre>
 
{{:QBWiki:Quick links/lingo}}
 
{{:QBWiki:Quick links/lingo}}
 
{{List lookup helper|QBWiki:Quick links/lingo}}
 
{{List lookup helper|QBWiki:Quick links/lingo}}
{{#var:length}}
+
{{#var:length}}, {{#var:invocations}}
  
 
{{#loop:jj|1|{{#var:length}}|{{#var:entry_{{#var:jj}}}}<br/>}}
 
{{#loop:jj|1|{{#var:length}}|{{#var:entry_{{#var:jj}}}}<br/>}}
Line 34: Line 36:
 
{{:QBWiki:Quick links/lingo}}
 
{{:QBWiki:Quick links/lingo}}
 
{{List lookup helper|QBWiki:Quick links/lingo}}
 
{{List lookup helper|QBWiki:Quick links/lingo}}
{{#var:length}}
+
{{#var:length}}, {{#var:invocations}}
  
 
{{#loop:jj|1|{{#var:length}}|{{#var:entry_{{#var:jj}}}}<br/>}}
 
{{#loop:jj|1|{{#var:length}}|{{#var:entry_{{#var:jj}}}}<br/>}}
 
}}</noinclude>
 
}}</noinclude>

Revision as of 19:03, 14 December 2025

Template documentation

Given a list page, loads it exactly once and sets up enough variables it will not need to be loaded again to retrieve any entry. If this template has been invoked before with the same page_name, no-op.

  • page_name - the page name provided as arg1
  • loaded_page - the text of page_name
  • length - the length of the list
  • entry_i - the entry in the list at position i, where i is in [1, length-1] (0-indexed)

There is also the housekeeping variable "invocations", which equals the number of times this template was resolved.

{{:QBWiki:Quick links/lingo}}
{{List lookup helper|QBWiki:Quick links/lingo}}
{{#var:length}}, {{#var:invocations}}

{{#loop:jj|1|{{#var:length}}|{{#var:entry_{{#var:jj}}}}<br/>}}


  • Wondering why people keep saying "m"?
  • Confused what a "vulcher" is?
  • Want to find out about "superpowers"?
  • Wondering just what makes something "important"?
  • Heard something about the "canon"?


5, 1

Wondering why people keep saying "m"?
Confused what a "vulcher" is?
Want to find out about "superpowers"?
Wondering just what makes something "important"?
Heard something about the "canon"?