Re: [pmwiki-users] Problem with conditional markup equal ?

2021-03-31 Thread Dominique Faure
Hi,

You could also have a try with the MarkupExprPlus recipe :

First, you'll need to set the $EnableExprVarManip flag set in your
configuration in order to enable variable evaluation in expressions.

Then, instead of relying on two distinct expressions as you have in
the "equal" condition, you could use the {(test equal ...)} enclosing
expression which should evaluate as expected in one shot.

Regards,
Dominique

On Tue, Mar 30, 2021 at 12:48 PM Benjamin Grassineau
 wrote:
>
> Hello list !
>
> I have a problem. I would like to test if two variables are equal to
> each other. One of them is stored in a page text variable, the other is
> "present" in the name of the page. It could be, more specifically, an
> existent or non-existent page (I desactivate the message of non-existent
> page, so, the "variable" is located in the adress bar).
>
>
> 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 ! 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 !
>
> Thanks for your help.
>
> Benjamin
>
>
> ___
> pmwiki-users mailing list
> pmwiki-users@pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users

___
pmwiki-users mailing list
pmwiki-users@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-users


Re: [pmwiki-users] Problem with conditional markup equal ?

2021-03-30 Thread Petko Yotov

On 30/03/2021 13:32, Petko Yotov wrote:

Can you demonstrate this on a subpage of


You don't need to demo this -- I've replied and forgot to delete this 
line.


Petko


___
pmwiki-users mailing list
pmwiki-users@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-users


Re: [pmwiki-users] Problem with conditional markup equal ?

2021-03-30 Thread Petko Yotov

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

___
pmwiki-users mailing list
pmwiki-users@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-users