01069: Last PTV of same name wins, it should be first

Summary: Last PTV of same name wins, it should be first
Created: 2009-02-02 06:29
Status: Awaiting feedback
Category: CoreCandidate
From: HansB
Priority: 51
Version: 2.2.0


If there are several PTVs with same name, the later one in the pattern array and in the page will be used. I think it would be more intuitive if the first PTV of same name will be used, as one often uses PTV for data at the top of a page, and does not want it to be corrupted by a later inclusion of a PTV with same name. For instance something like Name: fooo could have been easily added to a page anywhere, like in a comment later on, without the author being aware that it is a vital data PTV set in the top section.

Suggested Remedy:

A change to the core PageTextVar function adding code

if (isset($pc["=p_{$m[2]}"])) continue;

after line

foreach($match as $m) {

No, I really don't like this idea. It seems more intuitive to me that a later PTV will override an earlier one. So if you must add this feature, PLEASE make it optional. Kathryn Andersen July 08, 2009, at 12:58 PM

It is not even the last PTV which wins, it depends on the order of processing of the $PageTextVarPatterns array, first all name:value, next all (:name:value:), next if you have added custom (::name:value::) etc.

(:foo:foo is 1:)
foo: foo is 2
(:foo:foo is 3:)

bar: bar is 1
(:bar: bar is 2:)
bar: bar is 3
Foo is "{$:foo}" and bar is "{$:bar}".

foo: foo is 2

bar: bar is 1 bar: bar is 3

Foo is "foo is 3" and bar is "bar is 2".

So (:name:value:) overrides name:value, and if you have added yet another pattern, it overrides both. --Petko July 15, 2009, at 09:43 PM

Whatever we do we need to be consistent (principle of least surprise). Currently if asked I would have said that in a page the last (title, summary, PTV, ...) wins, so to speak. OTOH the first anchor (if multiple with the same name) is selected for include, pagelist, etc. simon July 16, 2009, at 04:20 PM

There is no such thing "multiple anchors with the same name", in HTML it is forbidden, if PmWiki finds such a markup, it just nukes it away. Unlike programming languages, where a variable could be redefined many times and the last one wins. --Petko August 26, 2009, at 07:25 PM

Don't know what I was thinking of, ahem Simon August 26, 2009, at 08:46 PM

Some suggestions/request:

  1. Support for retrieval of PTV from sections.
  2. Support for multiple PTV of same name on a page.

VKrishn May 16, 2010, at 04:26 PM