Difference between revisions of "Issue:Conditional clause in output?"
m |
|||
Line 27: | Line 27: | ||
|order=descending | |order=descending | ||
|count=10 | |count=10 | ||
− | |resultsheader= | + | |resultsheader=There are %TOTALPAGES% images in this category. |
|format=«gallery»\n,\n%PAGE%¦²{User:Subfader/Examples/Images used/Template¦%PAGE%}²,,\n«/gallery» | |format=«gallery»\n,\n%PAGE%¦²{User:Subfader/Examples/Images used/Template¦%PAGE%}²,,\n«/gallery» | ||
}} | }} | ||
Line 50: | Line 50: | ||
== Reply == | == Reply == | ||
+ | Found a solution myself :) | ||
+ | |||
+ | {{#dpl: | ||
+ | |category=Test Images | ||
+ | |namespace=Image | ||
+ | |ordermethod=firstedit | ||
+ | |order=descending | ||
+ | |count=10 | ||
+ | |resultsheader=There are %TOTALPAGES% images in this category. | ||
+ | |format=«gallery»\n,\n%PAGE%¦²{#ifexpr:²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² < 1 | ||
+ | ¦(This image is not used.) | ||
+ | ¦²{#ifexpr:²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² = 1 | ||
+ | ¦²{User:Subfader/Examples/Images used/Template¦%PAGE%}² | ||
+ | ¦([[:%PAGE%#filelinks|²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² pages use this image.]]) | ||
+ | }²}²,,\n«/gallery» | ||
+ | }} | ||
+ | It uses another template to return the number of pagelinks. So now it works like this: | ||
+ | |||
+ | [[User:Subfader/Examples/Images_used|Images used]]: | ||
+ | <pre> | ||
+ | {{#dpl: | ||
+ | |category=Test Images | ||
+ | |namespace=Image | ||
+ | |ordermethod=firstedit | ||
+ | |order=descending | ||
+ | |count=10 | ||
+ | |resultsheader=There are %TOTALPAGES% images in this category. | ||
+ | |format=«gallery»\n,\n%PAGE%¦²{#ifexpr:²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² < 1 | ||
+ | ¦(This image is not used.) | ||
+ | ¦²{#ifexpr:²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² = 1 | ||
+ | ¦²{User:Subfader/Examples/Images used/Template¦%PAGE%}² | ||
+ | ¦([[:%PAGE%#filelinks|²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² pages use this image.]]) | ||
+ | }²}²,,\n«/gallery» | ||
+ | }} | ||
+ | </pre> | ||
+ | |||
+ | which uses [[User:Subfader/Examples/Images_used/Template|Images used/Template]]: | ||
+ | <pre> | ||
+ | {{#dpl: | ||
+ | |debug=0 | ||
+ | |namespace= | ||
+ | |imageused={{{1}}} | ||
+ | |count=2 | ||
+ | |format=,[[%PAGE%]]<br>,, | ||
+ | }} | ||
+ | </pre> | ||
+ | |||
+ | which uses [[User:Subfader/Examples/Images_used/Template/Res|Images_used/Template/Res]]: | ||
+ | <pre> | ||
+ | {{#dpl: | ||
+ | |debug=0 | ||
+ | |namespace= | ||
+ | |imageused={{{1}}} | ||
+ | |noresultsheader=0 | ||
+ | |resultsheader=%TOTALPAGES% | ||
+ | |format=,,, | ||
+ | }} | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | '''Could you check if this correct? Maybe there's an easier way with including only one template.''' | ||
+ | <br>Feel free to close this bug and add this as new example :) |
Revision as of 18:52, 5 July 2009
Description: | |
Extension / Version: | DPL / 1.8.6 |
Type / Status: | Change Request / open |
Problem
Hi, I want to use an conditional clause in the output. The output should be different if there is no result, one result or multiple results. Example:
This calls images in Category:Test Images. It can later be used on category pages using category = PAGENAME. E.g. I Have disabled the Media section on Category pages cos the navigation sucks.
Atm it returns a gallery where the image links to its desc page and a list of links to the pages that use that image.
- Cookie.jpg is only used on one article only.
- Bob Ross.gif is used two articles.
- Placeholder.png is not used on any page.
How it works:
{{#dpl: |category=Test Images |namespace=Image |ordermethod=firstedit |order=descending |count=10 |resultsheader=There are %TOTALPAGES% images in this category. |format=«gallery»\n,\n%PAGE%¦²{User:Subfader/Examples/Images used/Template¦%PAGE%}²,,\n«/gallery» }}
The template to generate the article links =
{{#dpl: |debug=0 |namespace= |imageused={{{1}}} |count=2 |format=,[[%PAGE%]]<br>,, }}
Now the plan is:
- If the image is only used on page: Gallery text = Link to the page that uses the image (standard case for my usage)
- If the image is used on more than one page: Gallery text =
[[:File:%PAGE%#filelinks|X pages link to this image]]
(if counting the page links is expensive then "Multiple" is ok too) - If the image is unused: Gallery text = "This image is unused."
Reply
Found a solution myself :)
There are 4 images in this category.It uses another template to return the number of pagelinks. So now it works like this:
{{#dpl: |category=Test Images |namespace=Image |ordermethod=firstedit |order=descending |count=10 |resultsheader=There are %TOTALPAGES% images in this category. |format=«gallery»\n,\n%PAGE%¦²{#ifexpr:²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² < 1 ¦(This image is not used.) ¦²{#ifexpr:²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² = 1 ¦²{User:Subfader/Examples/Images used/Template¦%PAGE%}² ¦([[:%PAGE%#filelinks|²{User:Subfader/Examples/Images used/Template/Res¦%PAGE%}² pages use this image.]]) }²}²,,\n«/gallery» }}
which uses Images used/Template:
{{#dpl: |debug=0 |namespace= |imageused={{{1}}} |count=2 |format=,[[%PAGE%]]<br>,, }}
which uses Images_used/Template/Res:
{{#dpl: |debug=0 |namespace= |imageused={{{1}}} |noresultsheader=0 |resultsheader=%TOTALPAGES% |format=,,, }}
Could you check if this correct? Maybe there's an easier way with including only one template.
Feel free to close this bug and add this as new example :)