Difference between revisions of "Template:ExtractFirstPageNumber"

From Encyclopedia of Scientonomy
Jump to navigation Jump to search
(Created page with "<noinclude> Use this template to extract the first page number from a page-page string. For instance, if (e.g. "23-45"). E '''NOTE:''' As any "printing" template, it doesn'...")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
Use this template to extract the first page number from a page-page string. For instance, if (e.g. "23-45"). E
+
Use this template to extract the first page number from a page-page string. For instance, if <code><nowiki>pages="23-45"</nowiki></code>, the template will return 23. If <code><nowiki>pages="234"</nowiki></code>, the template will return 234. If an empty string is passed as a value, an empty string is returned.  
  
 
'''NOTE:''' As any "printing" template, it doesn't store any values anywhere, but merely prints them on the page.
 
'''NOTE:''' As any "printing" template, it doesn't store any values anywhere, but merely prints them on the page.
Line 9: Line 9:
 
</noinclude><includeonly><!--
 
</noinclude><includeonly><!--
 
-->{{#if: {{{pages|}}}|<!--  
 
-->{{#if: {{{pages|}}}|<!--  
   -->{{#vardefine: varSepPos|{{#pos: {{{pages}}}|-}}|}}<!--  
+
   -->{{#vardefine: varSepPos|{{#pos: {{{pages|}}}|-}}|}}<!--  
   -->{{#if: {{#var: varSepPos}}|<!--  
+
   -->{{#if: {{#var: varSepPos}}<!--  
   -->|<!-- separator is found: extract first page
+
   -->|<!-- separator is found: extract first page if the separator is not the first character
 
     --><!--  
 
     --><!--  
     -->{{#vardefine: varFirstPage|<!--
+
     -->{{#ifeq: {{#var: varSepPos}}|0<!--
       -->{{#sub: {{{pages}}}|0|{{#var: varSepPos}}|}}|<!--
+
    -->|<!-- separator is the first character: return empty string
     -->}}<!-- vardefine
+
      --><!--
 +
      -->{{#vardefine: varFirstPage|}}<!--  
 +
       --><!--
 +
    -->|<!-- separator is not the first character: extract the string
 +
      --><!--
 +
      -->{{#vardefine: varFirstPage|<!--
 +
        -->{{#sub: {{{pages}}}|0|{{#var: varSepPos}}|}}|<!--
 +
      -->}}<!-- vardefine
 +
      --><!--  
 +
     -->}}<!-- if separator is the first character 
 
     --><!--  
 
     --><!--  
 
   -->|<!-- separator is not found: take the whole value of page
 
   -->|<!-- separator is not found: take the whole value of page

Latest revision as of 05:27, 25 June 2017

Use this template to extract the first page number from a page-page string. For instance, if pages="23-45", the template will return 23. If pages="234", the template will return 234. If an empty string is passed as a value, an empty string is returned.

NOTE: As any "printing" template, it doesn't store any values anywhere, but merely prints them on the page.

Parameters:

  • |pages= - pages in the "xx-yy" format. E.g. "23-145", "1-34", "vi-ix", etc.