[pmwiki-users] Problem with conditional markup equal ?
Petko Yotov
5ko at 5ko.fr
Tue Mar 30 04:32:37 PDT 2021
Can you demonstrate this on a subpage of www.pmwiki.org/wiki/Test/Test ?
Petko
On 30/03/2021 12:47, Benjamin Grassineau wrote:
> In the group header, I test this, for example :
>
> - The name of the page where I will execute the test :
> Utilisateurs/InitGYheJLMrKtest
>
> - The value of the page text variable called $:ptv : GYheJLMrK. It is
> located in Utilisateurs.test
>
> - the conditional test : (:if equal "{(substr '{*$Name}' 4 9)}"
> "{Utilisateurs.{(substr '{*$Name}' 13)}$:ptv} ] ":) Great ! (:if:)
> Problem : the conditional markup "equal" doesn't work !
Here you have a typo " ] ":
"{Utilisateurs.{(substr '{*$Name}' 13)}$:ptv} ] "
You probably mean:
"{Utilisateurs.{(substr '{*$Name}' 13)}$:ptv}"
This will not fix it though.
> I don't have
> "Great". It is strange because both expressions work, independently of
> the test. I have the good result which is displayed in both case
> (GYheJLMrK in this example).
>
> Apparently, the problem come from the second term {(substr '{*$Name}'
> 13)} (I eliminated the other candidates).
>
> Does anyone have an idea of the origin of the problem: just the
> syntax, sequence of execution, php version ...? I block !
It comes from the order of processing of the markup rules.
Your markup, without the typo, is:
(:if equal "{(substr '{*$Name}' 4 9)}" "{Utilisateurs.{(substr
'{*$Name}' 13)}$:ptv}":)
PmWiki first finds and processes "{*$Name}" -- page variables and page
text variables. "{*$Name}" is "InitGYheJLMrKtest". At that point, your
markup becomes:
(:if equal "{(substr 'InitGYheJLMrKtest' 4 9)}" "{Utilisateurs.{(substr
'InitGYheJLMrKtest' 13)}$:ptv}":)
It then processes {(substr ...)} and other markup expressions, so your
text becomes:
(:if equal "GYheJLMrK" "{Utilisateurs.test$:ptv}":)
At that point, that conditional is false, the 2 compared strings are not
the same. It needs to do one additional round of processing, which it
does not now, but at a later point, after the conditional has been
evaluated (to false).
So at this point you would need to immediately reevaluate the output of
the markup expression as another pagevariable and pagetextvariable. This
is not standard -- can be done but I am not sure of the consequences --
but if you must have it, here it is:
In config.php:
Markup('{(', '>{$var}',
'/\\{(\\(\\w+\\b.*?\\))\\}/',
"MyMarkupMarkupExpression");
function MyMarkupMarkupExpression($m) {
extract($GLOBALS["MarkupToHTML"]); # get $pagename
return PRR(MarkupExpression($pagename, $m[1]));
}
This redefines the core MarkupExpressions rule to call your own
"MyMarkupMarkupExpression" function which then wraps the call in PRR()
"PmWiki redo rules". So the result of the markup expression will have
all previous markup rules re-applied from the start, including replacing
the $:ptv with its value.
As I said, I'm unsure of the implications -- this may break something
that works now. Or it might work.
Petko
More information about the pmwiki-users
mailing list