MarkupExpressionSamples-Talk

Summary: Talk page for MarkupExpressionSamples.
Maintainer:
Users: (View? / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

PHP8

math is a very usefull function... But is this not compatible with php8? In some cases I get: Parse error: syntax error, unexpected token "," in [last line] 2024-10-09 --Nitram

PHP8

I think all "number_format($args[0]..." has to be "number_format(floatval($args[0])..." ?

MX returning part of page text variable name used in conditional

I'm trying to use {(math )} and/or {(calc )} along with PmWiki's PTVs and conditional markup, buts not working as expected. I've tried this on a fresh new wiki install with no other recipes. Here's what I'm doing:

(:X:2:)
(:Y:2:)
(:X4Y4:10:)

(:if equal "{$:X4Y4}" "10":)
EQUAL
(:else:)
NOT EQUAL
(:ifend:)

above returns "EQUAL" as expected, but:

(:if equal "{$:X{(math {$:X} + {$:Y})}Y4}" "10":)
EQUAL
(:else:)
NOT EQUAL
(:ifend:)

returns "NOT EQUAL". Same with

(:if equal "{$:X{(calc '{$:X} + {$:Y}')}Y4}" "10":)
EQUAL
(:else:)
NOT EQUAL
(:ifend:)

This may be related to the order of processing of markup rules, page text variables come before markup expressions which come before conditionals: I suspect at the time the "equal" conditional is evaluated, the first argument is the text string "{$:X4Y4}" and not (yet) "10" which may be re-evaluated at a later point.

If you need complex calculations, it may be easier to write a custom conditional that is processed separately, see ConditionalMarkupSamples for examples; or a custom markup rule that outputs something based on other variables in the current page, see MarkupDirectiveFunctions for a quick start and Functions for PageTextVar(). --Petko


Talk page for the MarkupExpressionSamples recipe (users?).