Difference between revisions of "Example 1"
(46 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
− | Our demo web site contains some articles on ''fictitious countries'' (this is also the name of their common category). | + | With DPL you can do simple and useful things like [[Sort articles on people by last name]]. |
+ | |||
+ | But there is much more you can do. Our demo web site contains some articles on ''fictitious countries'' (this is also the name of their common category). | ||
{{#dpl:category=Fictitious country|addpagesize=true}} | {{#dpl:category=Fictitious country|addpagesize=true}} | ||
Line 5: | Line 7: | ||
They all use a template named "Country" which has parameters like ''capital''. The template produces a small table and a link to the country list we want to generate. There are chapters on religion and history in most of the articles. | They all use a template named "Country" which has parameters like ''capital''. The template produces a small table and a link to the country list we want to generate. There are chapters on religion and history in most of the articles. | ||
We show how to create a sortable wikitable list of those articles which gives some excerpts of the contents. | We show how to create a sortable wikitable list of those articles which gives some excerpts of the contents. | ||
− | |||
DPL can be used as a mediawiki parser '''extension''', which means that a special DPL tag is used: | DPL can be used as a mediawiki parser '''extension''', which means that a special DPL tag is used: | ||
Line 13: | Line 14: | ||
<DPL> | <DPL> | ||
category=Fictitious country | category=Fictitious country | ||
− | includepage={Country} dpl,#History,#Religion[20] | + | includepage={Country} dpl,#History,#Religion[20],revolution |
addpagecounter=true | addpagecounter=true | ||
− | + | format=¶{|class="wikitable sortable" ¶!Country ¶!Official Name ¶!Capital ¶!Dial Code ¶!History ¶!Religion ¶!Revolutions,¶|-¶|[[%PAGE%]] (%COUNT%),,¶|} | |
− | + | secseparators=¶| | |
− | secseparators= | ||
</DPL> | </DPL> | ||
</nowiki></pre> | </nowiki></pre> | ||
− | We select articles by category ("Fictitious Country") and explain that we want to see contents from the template "Country" and from two chapters. We truncate the text on religion to a maximum of | + | We select articles by category ("Fictitious Country") and explain that we want to see contents from the template "Country" and from two chapters. And we want to transclude text which is contained between special section markers named "revolution". We truncate the text on religion to a maximum of 20 characters. We create a sortable table which contains the article name (as a link) and its access frequency in the first column and the content pieces in the other columns. Note that at the end of truncated contents you will find a small arrow which links directly to the chapter from where the contents was taken. The formatting for the template variables is done in a special template which is by convention named after the original template plus a suffix ([[Template:Country dpl]] in our case). This template is very simple; it only presents the values for name, capital and dial code as columns of a table. The transcluded contents from the marked sections ("revolution") is not changed in any way. Note that only the text between the markers is transcluded, not the whole sentence. |
+ | |||
+ | As wiki syntax depends on line breaks we must use a symbol to represent a line break ("\n" or "¶" are possible) . | ||
===== country list ===== | ===== country list ===== | ||
<DPL> | <DPL> | ||
category=Fictitious country | category=Fictitious country | ||
− | includepage={Country} dpl,#History,#Religion[20] | + | includepage={Country} dpl,#History,#Religion[20],revolution |
addpagecounter=true | addpagecounter=true | ||
− | + | format=¶{|class="wikitable sortable" ¶!Country ¶!Official Name ¶!Capital ¶!Dial Code ¶!History ¶!Religion ¶!Revolutions,¶|-¶|[[%PAGE%]] (%COUNT%),,¶|} | |
− | + | secseparators=¶| | |
− | secseparators= | ||
</DPL> | </DPL> | ||
===== country list (2) ===== | ===== country list (2) ===== | ||
− | DPL can also be used as a mediawiki parser '''function''', which is more powerful as it allows DPL to be used within templates, parameters being template calls or variable expansions. The | + | DPL can also be used as a mediawiki parser '''function''', which is more powerful as it allows DPL to be used within templates, parameters being template calls or variable expansions. The syntax looks a bit different. |
+ | |||
+ | Special care must be taken if you need the pipe symbol ("|") as contents of your statements. This happens for example, when you want to define a wiki table. | ||
+ | '''We offer two ways for that purpose:''' | ||
+ | * the classic way, i.e. define special macros like <big>'''(!'''</big> with a contents of <big>'''{|'''</big> (this is common practice in wikipedia). | ||
+ | * use the special symbol '''¦'''; this symbol looks very similar to the pipe character and is therefore more elegant. | ||
+ | |||
+ | See two examples (with identical results) to understand the difference: | ||
− | ''parser function syntax'' | + | {| |
+ | !''parser function syntax with '''\n''' and '''macros''' | ||
+ | !''parser function syntax with '''¶''' and '''¦''' | ||
+ | |- | ||
+ | | | ||
<pre><nowiki> | <pre><nowiki> | ||
{{#dpl:category=Fictitious country | {{#dpl:category=Fictitious country | ||
− | |includepage={Country} dpl,#History[ | + | |includepage={Country} dpl,#History[80],#Religion |
|addpagecounter=true | |addpagecounter=true | ||
− | | | + | |format=\n{{(!}} class="wikitable sortable" |
− | |||
\n!Country | \n!Country | ||
\n!Official Name | \n!Official Name | ||
Line 49: | Line 60: | ||
\n!Dial Code | \n!Dial Code | ||
\n!History | \n!History | ||
− | \n!Religion | + | \n!Religion,\n{{!-}}\n{{!}}[[%PAGE%]] (%COUNT%),,\n{{!)}} |
− | + | |secseparators=\n{{!}} | |
− | |secseparators= | ||
}} | }} | ||
</nowiki></pre> | </nowiki></pre> | ||
Line 58: | Line 68: | ||
{{#dpl:category=Fictitious country | {{#dpl:category=Fictitious country | ||
− | |includepage={Country} dpl,#History[ | + | |includepage={Country} dpl,#History[80],#Religion |
|addpagecounter=true | |addpagecounter=true | ||
− | | | + | |format=\n{{(!}} class="wikitable sortable" |
− | |||
\n!Country | \n!Country | ||
\n!Official Name | \n!Official Name | ||
Line 67: | Line 76: | ||
\n!Dial Code | \n!Dial Code | ||
\n!History | \n!History | ||
− | \n!Religion | + | \n!Religion,\n{{!-}}\n{{!}}[[%PAGE%]] (%COUNT%),,\n{{!)}} |
− | + | |secseparators=\n{{!}} | |
− | |secseparators= | + | }} |
+ | |||
+ | | | ||
+ | <pre><nowiki> | ||
+ | {{#dpl:category=Fictitious country | ||
+ | |includepage={Country} dpl,#History[80],#Religion | ||
+ | |addpagecounter=true | ||
+ | |format=¶{¦ class="wikitable sortable" | ||
+ | ¶!Country | ||
+ | ¶!Official Name | ||
+ | ¶!Capital | ||
+ | ¶!Dial Code | ||
+ | ¶!History | ||
+ | ¶!Religion,¶¦-¶¦[[%PAGE%]] (%COUNT%),,¶¦} | ||
+ | |secseparators=¶¦ | ||
+ | }} | ||
+ | </nowiki></pre> | ||
+ | |||
+ | The result: | ||
+ | |||
+ | {{#dpl:category=Fictitious country | ||
+ | |includepage={Country} dpl,#History[80],#Religion | ||
+ | |addpagecounter=true | ||
+ | |format=¶{¦ class="wikitable sortable" | ||
+ | ¶!Country | ||
+ | ¶!Official Name | ||
+ | ¶!Capital | ||
+ | ¶!Dial Code | ||
+ | ¶!History | ||
+ | ¶!Religion,¶¦-¶¦[[%PAGE%]] (%COUNT%),,¶¦} | ||
+ | |secseparators=¶¦ | ||
}} | }} | ||
+ | |} | ||
'''Have a look at a more [[Example 2|realistic example]] ...''' | '''Have a look at a more [[Example 2|realistic example]] ...''' | ||
+ | [[Category:DPL Example|{{PAGENAME}}]] |
Latest revision as of 20:51, 22 August 2012
With DPL you can do simple and useful things like Sort articles on people by last name.
But there is much more you can do. Our demo web site contains some articles on fictitious countries (this is also the name of their common category).
- DPL Example 007 main page 1 [114 B]
- Nigunda [1 kB]
- Nigunda Test [454 B]
- Somango [663 B]
They all use a template named "Country" which has parameters like capital. The template produces a small table and a link to the country list we want to generate. There are chapters on religion and history in most of the articles. We show how to create a sortable wikitable list of those articles which gives some excerpts of the contents.
DPL can be used as a mediawiki parser extension, which means that a special DPL tag is used:
parser extension syntax
<DPL> category=Fictitious country includepage={Country} dpl,#History,#Religion[20],revolution addpagecounter=true format=¶{|class="wikitable sortable" ¶!Country ¶!Official Name ¶!Capital ¶!Dial Code ¶!History ¶!Religion ¶!Revolutions,¶|-¶|[[%PAGE%]] (%COUNT%),,¶|} secseparators=¶| </DPL>
We select articles by category ("Fictitious Country") and explain that we want to see contents from the template "Country" and from two chapters. And we want to transclude text which is contained between special section markers named "revolution". We truncate the text on religion to a maximum of 20 characters. We create a sortable table which contains the article name (as a link) and its access frequency in the first column and the content pieces in the other columns. Note that at the end of truncated contents you will find a small arrow which links directly to the chapter from where the contents was taken. The formatting for the template variables is done in a special template which is by convention named after the original template plus a suffix (Template:Country dpl in our case). This template is very simple; it only presents the values for name, capital and dial code as columns of a table. The transcluded contents from the marked sections ("revolution") is not changed in any way. Note that only the text between the markers is transcluded, not the whole sentence.
As wiki syntax depends on line breaks we must use a symbol to represent a line break ("\n" or "¶" are possible) .
country list
Country | Official Name | Capital | Dial Code | History | Religion | Revolutions |
---|---|---|---|---|---|---|
DPL Example 007 main page 1 (%COUNT%) | Template:Country dpl.default | |||||
Nigunda (%COUNT%) | Republic of Nigunda | Bamitogoo | 237 |
some facts about ..→ |
revolution in 1977 which lasted 10 days another revolution in 1987 which caused many deaths. | |
Nigunda Test (%COUNT%) | Republic of Nigunda Test | Bamitogoo Test | 237 |
Nigunda Test History - Chapter Sequence in the article doesn´t matter for DPL .. |
some facts about ..→ |
|
Somango (%COUNT%) | Somango Island | Aaaabququque | 224 |
a text on the history of Somango; a text on the history of Somango; a text on the history of Somango; |
some facts about ..→ |
Nothing to declare |
country list (2)
DPL can also be used as a mediawiki parser function, which is more powerful as it allows DPL to be used within templates, parameters being template calls or variable expansions. The syntax looks a bit different.
Special care must be taken if you need the pipe symbol ("|") as contents of your statements. This happens for example, when you want to define a wiki table. We offer two ways for that purpose:
- the classic way, i.e. define special macros like (! with a contents of {| (this is common practice in wikipedia).
- use the special symbol ¦; this symbol looks very similar to the pipe character and is therefore more elegant.
See two examples (with identical results) to understand the difference:
parser function syntax with \n and macros | parser function syntax with ¶ and ¦ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
{{#dpl:category=Fictitious country |includepage={Country} dpl,#History[80],#Religion |addpagecounter=true |format=\n{{(!}} class="wikitable sortable" \n!Country \n!Official Name \n!Capital \n!Dial Code \n!History \n!Religion,\n{{!-}}\n{{!}}[[%PAGE%]] (%COUNT%),,\n{{!)}} |secseparators=\n{{!}} }} The result:
|
{{#dpl:category=Fictitious country |includepage={Country} dpl,#History[80],#Religion |addpagecounter=true |format=¶{¦ class="wikitable sortable" ¶!Country ¶!Official Name ¶!Capital ¶!Dial Code ¶!History ¶!Religion,¶¦-¶¦[[%PAGE%]] (%COUNT%),,¶¦} |secseparators=¶¦ }} The result:
|
Have a look at a more realistic example ...