Difference between revisions of "Template:PrintFirstParagraph"

From Encyclopedia of Scientonomy
Jump to navigation Jump to search
(Created page with "<noinclude> This template is used to extract the first paragraph from a given text. '''NOTE:''' As any "printing" template, it doesn't store any values anywhere, but merely r...")
 
 
(25 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
This template is used to extract the first paragraph from a given text.
+
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 (&#8230;) is added.
  
 
'''NOTE:''' As any "printing" template, it doesn't store any values anywhere, but merely returns them.
 
'''NOTE:''' As any "printing" template, it doesn't store any values anywhere, but merely returns them.
Line 8: Line 8:
  
 
</noinclude><includeonly><!--
 
</noinclude><includeonly><!--
-->{{#if: {{#pos: {{{vartext|}}}|&#013;}}<!--
+
--><!-- 
  -->|{{#explode:{{{vartext|}}}|&#013;|0}}<!-- if there are two or more paragraphs
+
--><!-- exctract only the first 1000 characters
  -->|{{{vartext|}}}<!-- if there is one paragraph or less  
+
-->{{#vardefine: varTextShort|{{#sub: {{{vartext|}}}|0|1000}}|}}<!--
 +
--><!-- 
 +
--><!-- check if there is a paragraph sign
 +
-->{{#vardefine: varPos|{{#pos_e: {{#var: varTextShort}}|\n}}|}}<!--
 +
--><!--
 +
-->{{#if: {{#var: varPos}}<!--
 +
  -->|<!-- if there are two or more paragraphs
 +
  -->{{#explode_e: {{#var: varTextShort}}|\n|0}}<!--
 +
  -->|<!-- if there is one paragraph or less
 +
  -->{{#vardefine: varLen|{{#len: {{#var: varTextShort}} }}|}}<!--
 +
  --><!-- 
 +
  -->{{#ifexpr: {{#var: varLen}} > 997<!--
 +
    -->|{{#sub: {{#var: varTextShort}}|0|997}}&#8230;<!--
 +
    -->|{{#var: varTextShort}}<!--
 +
  -->}}<!-- ifexpr
 
-->}}<!-- if
 
-->}}<!-- if
 
--></includeonly>
 
--></includeonly>

Latest revision as of 17:46, 31 May 2020

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.