Difference between revisions of "Template:PrintFirstParagraph"
Jump to navigation
Jump to search
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 a <code><nowiki>...</nowiki></code> 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><!-- | ||
− | -->{{# | + | --><!-- check if there is a paragraph sign |
− | -->|{{#explode_e:{{{vartext|}}}|\n|0}}<!-- if there | + | -->{{#vardefine: varPos|{{#pos_e: {{{vartext|}}}|\n}}|}}<!-- |
− | + | --><!-- | |
− | -->}}<!-- | + | -->{{#if: {{#var: varPos}}<!-- |
+ | -->|<!-- if there are two or more paragraphs | ||
+ | -->{{#ifexpr: {{#var: varPos}} > 1000<!-- | ||
+ | -->|{{#sub: {{{vartext|}}}|0|997}}...<!-- | ||
+ | -->|{{#explode_e: {{{vartext|}}}|\n|0}}<!-- | ||
+ | -->}}<!-- | ||
+ | -->|<!-- if there is one paragraph or less | ||
+ | -->{{#ifexpr: {{#len: {{{vartext|}}}|}} > 1000<!-- | ||
+ | -->|{{#sub: {{{vartext|}}}|0|997}}...<!-- | ||
+ | -->|{{{vartext|}}}<!-- | ||
+ | -->}}<!-- | ||
+ | -->}}<!-- switch | ||
--></includeonly> | --></includeonly> |
Revision as of 23:45, 14 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 a ...
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.