Issue:Conditional clause in output?

From FollowTheScore
Revision as of 19:54, 5 July 2009 by Subfader (talk | contribs)
Jump to: navigation, search
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.
There are 4 images in Category:Test Images.


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:

Images used:

{{#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=,,,
}}

This also used directly in Images used to return the number of images in "(X images use this image.)"

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 :)