[pmwiki-users] Testing for an empty page text variable

Petko Yotov 5ko at 5ko.fr
Wed May 9 04:32:34 CDT 2012


On Tuesday 08 May 2012 21:47:09 Randy Brown wrote:
> I tried writing a custom markup expression to give me the length of MyPTV,
> but the function didn't work:
> 
>      # for example: {(ptvlen "{$FullName}" "$:MyPTV")}
> $MarkupExpr['ptvlen'] = 'PTVlen($args[0],$args[1])';
>      function PTVlen ($page, $ptv) {
>          $var=PageTextVar($page,'$:ptv');
>          return strlen($var);
>      }

Use this unstead:

  $MarkupExpr['ptvlen'] = 'PTVlen($args[0],$args[1])';
  function PTVlen ($page, $ptv) {
    $var=PageTextVar($page,$ptv); # no $: or quotes
    return strlen($var);   
  }

Then, in the page, use this markup expression:

  {(ptvlen "{$FullName}" "MyPTV")} # not $:MyPTV

Petko




More information about the pmwiki-users mailing list