Difference between revisions of "Issue:%PAGES% or %TOTALPAGES% in parser functions"

From FollowTheScore
Jump to: navigation, search
(New page: {{Issue |Type = Bug |Extension = DPL |Version = ? |Description = %PAGES% or %TOTALPAGES% in parser functions returns syntax error |Status = open }} == Problem == I ...)
 
 
(4 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
  |Version    = ?
 
  |Version    = ?
 
  |Description = %PAGES% or %TOTALPAGES% in parser functions returns syntax error
 
  |Description = %PAGES% or %TOTALPAGES% in parser functions returns syntax error
  |Status      = open
+
  |Status      = closed
 
}}
 
}}
  
Line 24: Line 24:
 
|resultsheader=%TOTALPAGES% are {{#ifexpr:%TOTALPAGES% < 10|less than 10 results|more than 10 results}}
 
|resultsheader=%TOTALPAGES% are {{#ifexpr:%TOTALPAGES% < 10|less than 10 results|more than 10 results}}
 
}}
 
}}
 +
  
 
Or via a template: [[User:Subfader/NavTemplate]]
 
Or via a template: [[User:Subfader/NavTemplate]]
Line 47: Line 48:
  
 
== Reply ==
 
== Reply ==
 +
 +
You missed an important concept in DPL: To make your DPL statement work correctly the wiki syntax of the #ifexpr shall only be evaluated AFTER the DPL statement has been parsed and executed (i.e. the number of matching pages must be known by then). To achieve this you have to avoid using double curly braces and pipe characters within the DPL statement - because the MW parser would inevitably expand these symbols together with the DPL statement. Instead you have to use special symbols which DPL will internally translate to double curly braces and pipe characters in a second pass (after the result of the DPL query has been calculated). The same holds true, btw., for angle brackets. See the manual for more details. Feeld free to add mor explanations or links to examples to the manual.
 +
 +
<pre><nowiki>
 +
{{#dpl:
 +
|category=Category
 +
|namespace=Category
 +
|count=5
 +
|resultsheader=%TOTALPAGES% are ²{#ifexpr:%TOTALPAGES% < 10¦less than 10 results¦more than 10 results}²
 +
}}
 +
</nowiki></pre>
 +
 +
The above statement will deliver the expected result:
 +
 +
{{#dpl:
 +
|category=Category
 +
|namespace=Category
 +
|count=5
 +
|resultsheader=%TOTALPAGES% are ²{#ifexpr:%TOTALPAGES% < 10¦less than 10 results¦more than 10 results}²
 +
}}
 +
 +
[[User:Gero|Gero]] 06:58, 9 May 2009 (UTC)
 +
 +
:Boah, big sorry for my major failure. I just started using DPL two weeks ago and I remember these special treatments but forgot about it. I would have never come to this since parser funcs work there as long as it's not using %PAGE% or %TOTALPAGES%. Now I understand why :). Cheers! --[[User:Subfader|Subfader]] 11:16, 9 May 2009 (UTC)
 +
 +
=== Additional Note ===
 +
There is an [[DPL_Example_013|example]] which shows how to flip through pages of a big result set. Maybe you can copy/paste this solution to your wiki.
 +
[[User:Gero|Gero]] 14:35, 14 May 2009 (UTC)

Latest revision as of 15:35, 14 May 2009

Description: %PAGES% or %TOTALPAGES% in parser functions returns syntax error
Extension / Version: DPL   /   ?
Type / Status: Bug   /   closed

Problem

I want to create a navigation template for long DPL result lists. In general no problem, but I fail at detecting the end of the list where no "Next" link should appear. So I'd actually use no link if: totalpages - offset <= count. Simplified example:

{{#dpl:
|category=Category
|namespace=Category
|count=5
|resultsheader=%TOTALPAGES% are {{#ifexpr:%TOTALPAGES% < 10|less than 10 results|more than 10 results}}
}}
9 are Expression error: Unrecognized punctuation character "%".


Or via a template: User:Subfader/NavTemplate

{{#dpl:
|category=Category
|namespace=Category
|count=5
|resultsheader={{User:Subfader/NavTemplate|count=5|totalpages=%TOTALPAGES%}}
}}

User:Subfader/NavTemplate:
{{{totalpages}}} are {{#ifexpr:{{{totalpages}}} < 10|less than 10 results|more than 10 results}}. {{{count}}} displayed.
9 are Expression error: Unrecognized punctuation character "%".. 5 displayed.


Any help would be appreciated. --Subfader 16:13, 8 May 2009 (UTC)

Reply

You missed an important concept in DPL: To make your DPL statement work correctly the wiki syntax of the #ifexpr shall only be evaluated AFTER the DPL statement has been parsed and executed (i.e. the number of matching pages must be known by then). To achieve this you have to avoid using double curly braces and pipe characters within the DPL statement - because the MW parser would inevitably expand these symbols together with the DPL statement. Instead you have to use special symbols which DPL will internally translate to double curly braces and pipe characters in a second pass (after the result of the DPL query has been calculated). The same holds true, btw., for angle brackets. See the manual for more details. Feeld free to add mor explanations or links to examples to the manual.

{{#dpl:
|category=Category
|namespace=Category
|count=5
|resultsheader=%TOTALPAGES% are ²{#ifexpr:%TOTALPAGES% < 10¦less than 10 results¦more than 10 results}²
}}

The above statement will deliver the expected result:

9 are less than 10 results

Gero 06:58, 9 May 2009 (UTC)

Boah, big sorry for my major failure. I just started using DPL two weeks ago and I remember these special treatments but forgot about it. I would have never come to this since parser funcs work there as long as it's not using %PAGE% or %TOTALPAGES%. Now I understand why :). Cheers! --Subfader 11:16, 9 May 2009 (UTC)

Additional Note

There is an example which shows how to flip through pages of a big result set. Maybe you can copy/paste this solution to your wiki. Gero 14:35, 14 May 2009 (UTC)