Difference between revisions of "Template:PrintFirstParagraph"

From Encyclopedia of Scientonomy
Jump to navigation Jump to search
Line 8: Line 8:
  
 
</noinclude><includeonly><!--
 
</noinclude><includeonly><!--
 +
--><!-- 
 +
--><!-- exctract only the first 1000 characters to avoid "String exceeds 1,000 character limit" error
 +
-->{{#vardefine: varTextShort|{{#sub: {{{vartext|}}}|0|1000}}|}}<!--
 +
--><!-- 
 
--><!-- check if there is a paragraph sign
 
--><!-- check if there is a paragraph sign
-->{{#vardefine: varPos|{{#pos_e: {{{vartext|}}}|\n}}|}}<!--
+
-->{{#vardefine: varPos|{{#pos_e: {{#var: varTextShort}}|\n}}|}}<!--
 
-->varpos={{#var: varPos}}<!--
 
-->varpos={{#var: varPos}}<!--
 
-->{{#if: {{#var: varPos}}<!--
 
-->{{#if: {{#var: varPos}}<!--
 
   -->|<!-- if there are two or more paragraphs
 
   -->|<!-- if there are two or more paragraphs
   -->{{#if: {{#expr: {{#var: varPos}} > 1000}}<!--
+
   -->{{#explode_e: {{#var: varTextShort}}|\n|0}}<!--  
    -->|{{#sub: {{{vartext|}}}|0|997}}<!--
 
    -->|{{#explode_e: {{{vartext|}}}|\n|0}}<!--  
 
  -->}}<!-- ifexpr
 
 
   -->|<!-- if there is one paragraph or less
 
   -->|<!-- if there is one paragraph or less
 
   --><!--   
 
   --><!--   
   -->{{#vardefine: varLen|{{#len: {{{vartext|}}} }}|}}<!--
+
   -->{{#vardefine: varLen|{{#len: {{#var: varTextShort}} }}|}}<!--
 
   -->varlen={{#var: varLen}}<!--   
 
   -->varlen={{#var: varLen}}<!--   
   -->{{#if: {{#expr: {{#var: varLen}} > 1000}}<!--
+
   -->{{#if: {{#expr: {{#var: varLen}} > 997}}<!--
     -->|greater{{#sub: {{{vartext|}}}|0|997}}<!--
+
     -->|greater{{#sub: {{#var: varTextShort}}|0|997}}&#8230;<!--
 
     -->|less{{{vartext|}}}<!--  
 
     -->|less{{{vartext|}}}<!--  
 
   -->}}<!-- ifexpr
 
   -->}}<!-- ifexpr
 
-->}}<!-- if
 
-->}}<!-- if
 
--></includeonly>
 
--></includeonly>

Revision as of 00:18, 15 March 2018

This template is used to extract the first paragraph from a given text. If the first paragraph of the text is longer than 1000 characters, only the first 997 characters are returned, and an ellipsis (…) is added.

NOTE: As any "printing" template, it doesn't store any values anywhere, but merely returns them.

Parameters:

  • |vartext= - the text to extract the first paragraph from.